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

Click Detector problem in server?

Asked by
Paldi 109
10 years ago

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) 
0
You cannot access LocalPlayer through regular scripts VariadicFunction 335 — 10y

1 answer

Log in to vote
0
Answered by
RoboFrog 400 Moderation Voter
10 years ago

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) 
0
thank both of you! Paldi 109 — 10y
Ad

Answer this question