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

Click Detector problem in server?

When i test it in edit (play solo) it works fine but when i publish it and go in a online server, i get this error in the server output : Workspace.Merchant.Shop.ClickDetector.Shop:3 attempt to index local 'player' (a nil value)

this is the script (not a local script)

function onTouched() 
   local player = game.Players.LocalPlayer
player.PlayerGui.Shop.Shop.Visible = true
end 

script.Parent.MouseClick:connect(onTouched) 

1 comment

0

You cannot access LocalPlayer through regular scripts

1 answer

✓ Accepted answer

Like zach785 stated, LocalPlayer is only accessible in Play Solo or Local Scripts. However, to rectify the issue, all you need to do is get a return from your function to see who clicked it.

function onTouched(hit) -- "hit" will return game.Players."PlayerWhoClicked"
	hit.PlayerGui.Shop.Shop.Visible = true
end 

script.Parent.MouseClick:connect(onTouched) 

1 comment

0

thank both of you!

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