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

My "if kill enemy get coins" script wont work! Can anybody help?

Asked by 2 years ago
function ded(hahadedgobrrr)
    game.Players.LocalPlayer.leaderstats.XP.Value = game.Players.LocalPlayer.leaderstats.XP.Value + 25
end

script.Parent.Humanoid.Died:Connect(ded)

Code above

Im trying to make an rpg but this no work!

2 answers

Log in to vote
0
Answered by
0hsa 193
2 years ago
local xp_stat = game:GetService("Players").LocalPlayer:WaitForChild("leaderstats"):WaitForChild("XP")
local humanoid = script.Parent:FindFirstChildOfClass("Humanoid") or script.Parent:WaitForChild("Humanoid")

coroutine.wrap(function()
    humanoid.Died:Wait()
    xp_stat.Value += 1
end)()

might have grammar errors, i wrote this from the comments

0
oof snowpototoy 37 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

You cannot add stats from a local script. This allows exploiters to instantly give themselves inf exp.

-- make sure this is in a server script
game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanid = character:WaitForChild'Humanoid'

        humanoid.Died:Connect(function()
            player.leaderstats.XP.Value += 25
        end
    end)
end)
0
buti did not even use one snowpototoy 37 — 2y
0
1st off spelling error 2nd off it thinks you forgot to close function at line 6 then 3rd is some stuff is expected to stop at line 2 or something snowpototoy 37 — 2y

Answer this question