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

How do you make a localscript function with PlayerAdded?

PlayerAdded doesn't work in a localscript, but I need a localscript in order to make my game work. Can someone help me? This is what I have:

--Location: game.Workspace
--This is a localscript
function plradded(plr)
local gui=Lighting.Gui:Clone()
gui.Parent=plr.PlayerGui
wait(3)
gui=nil
end
game.Players.PlayerAdded:connect(plradded)

2 answers

✓ Accepted answer

The other way works, But easiest fix is changing PlayerAdded to ChildAdded. This should work in LS, and look like this...

--Location: game.Workspace
--This is a localscript
function plradded(plr)
local gui=Lighting.Gui:Clone()
gui.Parent=plr.PlayerGui
wait(3)
gui=nil
end
game.Players.ChildAdded:connect(plradded)

2 comments

0

Oh, I didn't think of that.

0

Thumbs up if you can xD

Use two different scripts and then use RemoteObjects (RemoteEvent/RemoteFunction) if you need them to work together

3 comments

0

I don't know what RemoteObjects is, would you mind explaining?

0

Actually, that's good enough for me. Thanks!

0

(RemoteObjects are used for server/client communication)

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