Another playergui problem

Pretty sure I did everything right, but I always seem to have an issue when accessing playergui

Here is my localscript, dont know why it’s not working. Could anyone please help?

local Players = game:GetService("Players")


script.Parent.Touched:Connect(function()
	game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = true
	game.Workspace.Rocket:Play()
	wait(2)
	game.Players.LocalPlayer.PlayerGui.ScreenGui.Enabled = false
	game.Workspace.Rocket:Stop()

end)

is this a local script or serverscript?

its a localscript. should it be a server script?

no, it should be in a localscript,
i was just making sure.

what is the localscript placed inside?

Where is the localscript located? If it’s in a part in the workspace it won’t run.

1 Like

its in a part thats in a folder thats in workspace. How can i fix this.

Use a serverscript, but you can’t use localplayer in a serverscript. Touched event gives you the part that touched the object so you can use that to find the player.

local Part=workspace.Part -- DEFINE YOUR PART

--[[]]--
local Player=game.Players.LocalPlayer
local Debounce=false
Part.Touched:Connect(function(Hit)
	if Player.Character and Hit.Parent==Player.Character then
		if Debounce==false then Debounce=true
			Player.PlayerGui.ScreenGui.Enabled = true
			game.Workspace.Rocket:Play()
			wait(2)
			Player.PlayerGui.ScreenGui.Enabled = false
			game.Workspace.Rocket:Stop()
			Debounce=false
		end
	end
end)

Place this in a LocalScript in StarterPlayerScripts

2 Likes