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

I got this scrip to work in Roblox studio but when I join the game from Roblox it is't working?

this is the script: part = script.Parent part.Touched:connect(function(hit) player = game:GetService("Players").LocalPlayer stats = player:findFirstChild("leaderstats") coins = stats:findFirstChild("Coins") coins.Value = coins.Value + 1
end)

and yes I have a leaderboard script

1 comment

0

You can only use local player in a local script

1 answer

✓ Accepted answer

Whenever doing a touched function you can not use LocalPlayer as it only works in LocalScripts

This code here should work:

script.Parent.Touched:connect(function(part)
	if game.Players:FindFirstChild(part.Parent.Name) then
		local plr = game.Players:FindFirstChild(part.Parent.Name)
		plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1
	end
end)

2 comments

0

thanks

0

if it worked then click "Accept Answer"

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