Script does not run when game start's [SOLVED]

I was trying to make a Test game for a Gui, But it didn’t work. The script of the code would not run and there were no errors in the output.

The gui wouldn’t pop up when the game ran.

My Script:

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

if Player.UserId == 230707182 then

	wait(4)			

	Player.PlayerGui.DialogGui.Enabled = true			

	wait(2)			

	Player.PlayerGui.DialogGui.Text.Text = "Have a good day owner :)"		

	wait(3)			

	Player.PlayerGui.DialogGui:Destroy()			

else			

	wait(4)			

	Player.PlayerGui.DialogGui.Enabled = true			

	wait(1)			

	Player.PlayerGui.DialogGui.Text.Text = "Wait..."			

	wait(3)			

	Player.PlayerGui.DialogGui.Text.Text = "You are not the owner..."			

	wait(3)			

	Player.PlayerGui.DialogGui.Text.Text = "..."			

	wait(3)			

	Player.PlayerGui.DialogGui:Destroy()			

	script.Boom:Play()			

	wait(2)			

	Player:Kick("Get out! Sincerly Luigi.")			

end

end)

Where your script is placed inside the game’s object tree is very important. Where is it (is it in the Workspace?, ServerScriptService), and is it a client, local or module script?

It is Placed inside the StarterGui along with the DialogGui. And it is a ServerScript too.

Serverscripts will not run on your client. Which is what it appears you need in this situation. Please try putting that code into a localscript.

1 Like

If it is a server script it won’t work, try using local scripts for UI.

Works now. I switched it to LocalPlayer instead of PlayerAdded and it works thanks.

1 Like