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

Script is not enabling when player joins?

Asked by 4 years ago
game.Players.PlayerAdded:Connect(function()
local plr = script.Parent
plr.Enabled = true
end)

This is a shorten version of the full script. This local script is inside a screengui. I want the screengui to be enabled but it doesnt work. Please help!

3 answers

Log in to vote
1
Answered by 4 years ago

Hey, RebornedSnoop

The reason that your PlayerAdded event is not firing is that when on the client-side, the code will not fire when the client joins. The event actually fires when a new player joins. So plr.Enabled would not actually become true until a new player joins. To prevent this, I suggest using the PlayerAdded event on the server when you can. You can then proceed to connect the event to the client through a RemoteEvent. If you MUST use the client, then instead of wrapping it in a function, just get rid of the function and the script will play as soon as the code loads.

Ad
Log in to vote
1
Answered by 4 years ago

Another way you could do this is putting the ui in replicated and cloning it:

game.Players.PlayerAdded:Connect(function(Player)

local UI = game.ReplicatedStorage.UI:Clone()
UI.Parent = Player.PlayerGui

end)
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The game.Players.PlayerAdded event does not work on the server. I would recommend to use that event on the server and then fire to the client using a remote event. Then, on the client enable the gui when the remote event is fired.

Answer this question