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

Why wont this script enable the player gui when told?

So I wrote out this code, but for some reason it won't work.

game.Players.PlayerAdded:Connect(function()
	local Player = game.Players.LocalPlayer
	if Player:IsInGroup(4324101) then
		Player.PlayerGui.Spawn.Enabled = true
	end
end)

Any ideas as to why? The script is a local script and no output errors.

3 comments

0

PlayerAdded won't fire for the local player because by the time the script is locally executed the player has already joined the game. Why do you need line 1 and 6? Remove them.

0

You do realize this could have been done in a single statement: Player.PlayerGui.Spawn.Enabled = Player:IsInGroup(4324101) Still not secure though, exploiters can easily enable it even if they're not in the group. Can't find a way to stop them.

0

Oof, thanks!

1 answer

You do not necessarily need the PlayerAdded event here at all. Since you are using a local script to check whether the LocalPlayer is in a group, you can simply do just that:

local player = game.Players.LocalPlayer

if player:IsInGroup(4324101) then
	player.PlayerGui.Spawn.Enabled = true
end

The issue with your current set up is that the PlayerAdded event may not fire after the local script is placed properly. Additionally, the function passed in Connect will also be called every time a new player joins, which may not be desirable.

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