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

How Do I make a script for Entered?

Asked by
PixelYT 30
9 years ago

So I'm trying to make a script that will pop up a GUI only when the player enters. Not when the player respawns.

This is what a tried.

function onEntered(player)
game.Players.PlayerAdded:connect(onEntered) --Problem should be here.

local Ent = Instance.new("ScreenGui")
Ent.Parent = game.Players.LocalPlayer.PlayerGui --This is just the first part of my GUI script.

end

When I test it there are no errors in the output.

Pleas help!

1 answer

Log in to vote
1
Answered by 9 years ago

I noticed you are doing something wrong, the event isnt supposed to be inside the connected function. So at start, it would be:

function onEntered(player)

end
game.Players.PlayerAdded:connect(onEntered)

And another thing i noticed, is that you are using a localscript, that won't fix your problem. Put a script at workspace, and then, ur code, fixed the way i did and: FULL CODE:

function onEntered(player)
local Ent = Instance.new("ScreenGui")
Ent.Parent = player:WaitForChild('PlayerGui')
end
game.Players.PlayerAdded:connect(onEntered)

Why WaitForChild?, WaitForChild so it can load . Why player.PlayerGui?, LocalPlayer in localscripts gives to the current player, and not new player, so that is kinda a messup (even tough in this case it would work, this is most recommended).

Hope it works! If not tell output. ~marcoantoniosantos3

Ad

Answer this question