Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Need help with cash on kill script which is not working?

Asked by 3 years ago

Im trying to do this script where when you kill someone, you get cash, im trying to do it without making a new folder, but its not working, can someone help me.

game.Players.PlayerAdded:connect(function(player) local folder = "leaderstats" local currency1 = "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)

0
wait 5 mins Ill answer nikitos54327 70 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

When you say "without making a new folder", I am assuming that you have already made the folder so. on lines 2 and 3, you identify the variables "folder" and "currency1" as strings. You then later attempt to access the value from it. But you can't because it's a string. I think you meant to access the strings from the actual player

game.Players.PlayerAdded:connect(function(player)
    local folder = player:WaitForChild("leaderstats") -- waiting for the CHILD leaderstats IN the player, not just a string 
    local currency1 = leaderstats:WaitForChild("Cash") -- assuming that cash is in leaderstats, waiting for a child named "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 -- you can now access the value, since the variable is an actual instance rather than a string
                end 
            end 
        end) 
    end) 
end)

If that does not work, then see if anything is coming up in the output

1
ty CalarqnicKen 8 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Heres the script I used

game.Players.PlayerAdded:connect(function(player)
 local leaderstats = Instance.new("Folder",player)
 leaderstats.Name = "leaderstats"

 local currency1 = Instance.new("IntValue",leaderstats)
 currency1.Name = "Money"
 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 + 100 --This is the reward after the player died.
    end
   end
  end)
 end)
    local kills  = Instance.new("NumberValue", leaderstats)
    kills.Name = "Kills"
    kills.Value = 0

    local deaths = Instance.new("NumberValue", leaderstats)
    deaths.Name = "Deaths"
    deaths.Value = 0

    player.CharacterAdded:Connect(function(character)
        local humanoid = character:FindFirstChild("Humanoid")

        humanoid.Died:Connect(function(died)
            deaths.Value = deaths.Value + 1
            local tag = humanoid:FindFirstChild("creator")
            local killer = tag.Value
            if tag and killer then
                killer.leaderstats:FindFirstChild("Kills").Value = killer.leaderstats:FindFirstChild("Kills").Value + 1
            end
        end)
    end)
end)

there's also deaths and kills

Answer this question