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

How do i fix scripts working in studio but not in game when im using local player?

I'm trying to make a game so that when you step on a hat it gives you RAP I tried this script it works in studio but not in-game is there any way to fix this

function onTouched(hit)
	local player = game.Players.LocalPlayer
	player.leaderstats.RAP.Value=player.leaderstats.RAP.Value+90
	script.Parent:Destroy()
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

game.Players.LocalPlayer only works in a local script not in a script so you can use the hit part of the function for example

function onTouched(hit)
local player = game.Players[hit.Parent.Name]
player.leaderstats.RAP.Value=player.leaderstats.RAP.Value+90
script.Parent:Destroy()
end

script.Parent.Touched:connect(onTouched)

hoped this helps :)

1 comment

0

Thanks it works now (:

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