Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

1 comment

0

oof

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)

2 comments

0

buti did not even use one

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

This discussion is preserved as it was. New answers, comments, and votes are closed.