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

ServerScriptService.Main:492: attempt to index local 'player' (a nil value) Error, help?

ServerScriptService.Main:492: attempt to index local 'player' (a nil value) Error I am trying to have a OnClientEvent Run in a ServerScript in my Main Script that runs the whole script. I original had it OnServerEvent but I need the server to send it to the Client Side. so I changed it to OnClientEvent

local Event = game.workspace.LevelUp
Event.OnClientEvent:connect(function(player)
player.PlayerGui.MainGui.LevelUpFrame.Visible = true
end)

1 answer

✓ Accepted answer

OnServerEvent has the player passed to it by roblox as its first arg since it knows who sent the request. OnClientEvent will not have the player passed as an arg since the client knows who it is and that the request is from the server.

OnClientEvent will also only work in a local script and will error if used in a server script. Use a BindableEvent for script to script requests on the same host.

Probably the best solution for you is to create a local script in the gui or add the additional code to include the remote event request since you will have access to all of the gui.

Example local script placed in LevelUpFrame

workspace:WaitForChild('LevelUp').OnClientEvent:Connect(function() -- the args sent to the client
	script.Parent.Visible = true -- show the LevelUpFrame frame
end)

I hope this helps please comment if you have any questions about this code.

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