So, I am making a Roblox game and it's a battle game. I want to make a cash for kill script, meaning every kill, the KILLER gets +10 cash, and you start off with 0 cash. The name on the leaderboard should be Cash. Can someone please make a script for this? I've tried everything on the web, so I hope you guys can help. Please include the leaderboard Cash in the script. Thanks in advance!
Update
I've included the code for the script, but instead of giving me the cash, it gives the killed person cash. How can I fix this?
Here is the code:
game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue",folder)
currency1.Name = "Cash"
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10 --This is the reward after the player died.
end
end
end)
end)
end)
You increase the amount of money in currency1. But currency1 belongs to player, who is the who has .Died!
Assuming creator is an ObjectValue whose Value is the Player instance of the killer, we can get that player's "Cash" to increase:
....
if tag ~= nil then
local killer = tag.Value
if killer ~= nil then
-- Find the killer's leaderstats folder
local killerStats = killer:FindFirstChild("leaderstats")
if killerStats ~= nil then
-- Find the killer's Cash IntValue
local killerCash = killerStats:FindFirstChild("Cash")
-- Increase cash as before
killerCash.Value = killerCash.Value + 10
end
end
end
......
This is a bit of a complex task if you have no experience with scripting. This requires your weapon system to keep track of who kills, and feed that into the leaderboard.
If you use default Roblox weapons, this functionality is likely already in your weapons. If you are making custom weapons, you need to implement this yourself.
I suggest you check out the Roblox Wiki for an example of Leaderboards. This is a relevant article about Leaderboards.
There are also going to be plenty of leaderboards in the Toolbox that you can edit to your needs. The default Leaderboard found in the "Roblox Sets" section of the Leaderboard increases a counter named "Kills" upon kills (with default Roblox weapons), and you can edit this to increase Cash instead. However - again - depends on how you keep track of your kills.
Next time please provide code and/or more detailed description of what you have already tried, so it is easier for us to help you understand or give you pointers. Right now it looks like you haven't really searched on your own and just posted your question here right away.
Related
So I have a roblox puzzle game that I have been working on for a while now on based on the arcade classic Q bert where the goal is to change all the colours of the bricks while avoiding enemies and getting a high score but I will be adding some features of my own so it does not get as repetitive such as additional tasks like collecting keys on platforms to unlock the door to the next level and secrets like a diamond that rarely appears once every 10 rounds and collecting one gives the player an extra dude and 10 million points.
This is how the game looks so far https://streamable.com/na46cu
The issue I am having as you can see is that the colours do in fact change but when I jump on it again it changes back to the first colour it changes to which in this case is green but I want it to stay on the first colour and make it so that it does not change until the player jumps on the brick again and later on in the game I want it to become more complex and puzzle like as the game goes on like in this example [https://www.youtube.com/watch?v=9eXJWiNXpOo][2] .
I have tried a few things like adding timers ,debounces and even separate scripts alltogether none of which have worked out for me so far and I of course went out looking for a question from somebody else that had a similar problem but so far I have been struggling to find anybody else that has the same problem.
local module = {} --module for the modulescript and for loop is created
local CollectionService = game:GetService("CollectionService")
for _, part,brick in pairs (CollectionService:GetTagged("blocks"))
do
part.Touched:Connect(function(hit) --Part connects with the touched property to the function with the parameter hit
if (hit.Parent:FindFirstChild("Humanoid"))
then
part.BrickColor = BrickColor.new ("Bright green")
wait (2)
part.BrickColor = BrickColor.new ("Eggplant")
-- local sound = workspace.Sound -- use "local sound = workspace.Sound", if there is already a sound object in the workspace
--sound.SoundId = "rbxassetid://4797903038" --replace quoted text with whatever sound id you need to use
--sound:Play()
end
end)
end
-- end)
--end
return module
I am not the best programmer but I do know the basics of programming and I have tried out various programming languages like Python and c++ all of which are not all that hard to understand once you know the basics of it all but finding out the solution to the problem is the really tricky part and so is bug fixing and troubleshooting.
I do know I could try a simple debounce system but that still does not solve the problem and it only makes it so the code only runs once and slows it down.
I have been asking all over the place for a solution to this problem but I never got an answer to it so I am trying on good old Stackoverflow for once to see if this will be the place where I get the help I need.
this should work, try it
local module = {} --module for the modulescript and for loop is created
local CollectionService = game:GetService("CollectionService")
local DidParts = {} -- Initializing another table to check if the part is already in it
for _, part,brick in pairs(CollectionService:GetTagged("blocks")) do
part.Touched:Connect(function(hit) --Part connects with the touched property to the function with the parameter hit
if hit.Parent:FindFirstChild("Humanoid") then
if table.find(DidParts,part) then
return -- checking if the part isnt in the table if it is then return
end
part.BrickColor = BrickColor.new("Bright green")
wait(2)
part.BrickColor = BrickColor.new("Eggplant")
table.insert(DidParts,part) -- when all the code has finished insert it in the table
-- local sound = workspace.Sound -- use "local sound = workspace.Sound", if there is already a sound object in the workspace
--sound.SoundId = "rbxassetid://4797903038" --replace quoted text with whatever sound id you need to use
--sound:Play()
end
end)
end
-- end)
--end
return module
I have my leader board but when i run this it gives me this error:
attempt to index nil with 'leaderstats'
local me = script.Parent
local function GiveMoney(part)
local hum = part.Parent:FindFirstChild("Humanoid")
if hum then
local money = player.leaderstats.Money
money.Value = money.Value + 1
me:Destroy()
end
end
me.Touched:Connect(GiveMoney)
local money = player.leaderstats.Money
or more specifically player.leaderstats causes that error. because player is a nil value and indexing nil values is not allowed as it does not make any sense.
Usually Humanoid's parent is a Model, stored as the Player instance's Character property.
Please read the Roblox documentation and search the web to find out how to access leaderboards and players.
local money = player.leaderstats.Money
I think you forgot to reference "player" because I can't see player variable anywhere
So, what I'm trying to make is a simple sword fighting game. I am following the tutorials of a YouTuber called AlvinBlox. I identically copied down his datastore code, while trying to learn what the code does, and the code is supposed to save the currency when the player leaves the game. For example, if you were to leave the game with 50 money, the server is supposed to save that money, and once you enter the game again, the saved data or money loads and you get ur original amount of money back. Well, in my situation that's not happening, whenever I join a game and go to the console to give myself a set amount of money, then I rejoin the game only to find out the data isn't saved at all. This is only a part of my actual stats script if you wish to see more let me know. To let you know, i also added this, "local dataStores = game:GetService("DataStoreService"):GetDataStore("MunnyDataStore")", at the very top of my code. Please help me, thank you!
local player_data
pcall(function()
player_data = dataStores:GetAsync(player.UserId.."-Munny")
end)
if player_data ~= nil then
-- Player has saved data, load it in
munny.Value = player_data
else
-- Else new player
munny.Value = defaultCash
end
local bindableEvent = Instance.new("BindableEvent")
game.Players.PlayerRemoving:Connect(function(player)
pcall(function()
dataStores:SetAsync(player.UserId.."-Munny",player.leaderstats.Munny.Value)
print("Saved")
playersLeft -= 1
bindableEvent:Fire()
end)
end)
game:BindToClose(function()
while playersLeft > 0 do
bindableEvent.Event:Wait()
end
end)
So, I am making a Roblox game and it's a battle game. I want to make a cash for kill script, meaning every kill, the KILLER gets +10 cash, and you start off with 0 cash. I've already got a script, see below. I tried everything on the Internet, but NOTHING works. Even the ones from the toolbox. But instead of giving the killer the cash, it gives the killed person cash! I don't want it to be a death for kill script! Here is the code I have another question like this, it will not help. It wasn't useful(It has the leaderboard, and the killed person gets +10 cash.):
game.Players.PlayerAdded:connect(function(player)
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local currency1 = Instance.new("IntValue",folder)
currency1.Name = "Cash"
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
if tag.Value ~= nil then
currency1.Value = currency1.Value + 10 --This is the reward after the
player died.
end
end
end)
end)
end)
Thanks in advance and I hope you guys can help!
There's no way to determine that player A killed player B without keeping track of that information manually.
For example, if player A shoots a gun, the bullet that it spawns could have an added ObjectValue with a Value of player A's humanoid.
When the bullet collides with player B, you would have an easy reference back to player A and can credit them for the KO.
I am making a game that has different walkspeeds in different sections, but I don't want people to change their own walkspeed with hacks. My solution was to make a part and stretch it to fit the entire area and make it invisible + CanCollide disabled, and then use the child script to kill you if your walkspeed isn't what it should be:
script.Parent.Touched:connect(function(WSChecker)
if not WSChecker.Parent then return end
local humanoid = WSChecker.Parent:FindFirstChild("Humanoid")
if not humanoid then return end
if (humanoid.WalkSpeed ~= 25) then
humanoid.Health = 0
end
end)
Problem is that it does not work with multiple players in the part at one time, and I want to make it so it will kick the player instead of killing them. Is there a way to go about these problems? It has to check their ws only within the part, and I don't know how to make it kick whoever changed their ws instead of killing them.
I would suggest hooking up your function to each player's Humanoid instead, and use the Humanoid.Running event.
Humanoid.Running provides you the speed they're currently running at, which means you can check if that speed is ever above a certain threshold, and punish them if it is.
Code example:
player.Character.Humanoid.Running:Connect(function(Speed)
print(Player, "is running at speed", Speed)
end)
As for kicking, you want to use player:Kick().
if (humanoid.WalkSpeed ~= 25) then
game.Players.LocalPlayer:Kick()
end
that should do the trick...
I think I can help. The solution that worked for me is:
local player = game.Players.LocalPlayer --Make sure it's a local script.
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local hum2 = char.Humanoid
script.Parent = game.StarterPlayer.StarterPlayerScripts
if hum.WalkSpeed >16 then
player:Kick('You have been kicked for possible speed hacks.')
end
if hum2.WalkSpeed >16 then
player:Kick('You have been kicked for possible speed hacks.')
end
if (humanoid.WalkSpeed ~= 25) then
game.localplayer.remove:fire
end
end)
Hopefully, this is a better solution.
You can ofcourse do the above but as an addition to what everyone above said, checking if the walkspeed value is at the desired value is easily bypassable.
Exploiters will get the raw metatable of the game and hook __index to return a normal value for WalkSpeed. Metatables cant be detected either as most modern exploits use C closures instead of Lua. Your best chance is to see how fast the character is moving and teleport them back if player is moving too fast (like a passive anticheat).