Why is this script not working?

I was making a script that would make a GUI open when a part is touched. Here is my script:

script.Parent.Touched:Connect(function()
	game.StarterGui.PC_INTERFACE.Frame.Visible = true
end)

For some reason, the script doesn’t work, and when I touch the part, it doesn’t do anything. Please help!

When the game loads, it moves everything from StarterGui into PlayerGui. Maybe try using this.

local Players = game:FindService("Players")

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid ~= nil then
		local player = Players:GetPlayerFromCharacter(humanoid.Parent)
		player.PlayerGui.PC_INTERFACE:WaitForChild("Frame").Visible = true
	end
end)

Hope this helps

2 Likes

Thanks! I believe this is the solution I was looking for!

You could also try:

function E(hit)
hum = hit.Parent:FindFirstChild(“Humanoid”)
if hum then
plr = game.Players:GetPlayerFromCharacter(hum.Parent)
plr.PlayerGui.PC_INTERFACE.Frame.Visible = true
end
end

script.Parent.Touched:Connect(E)

1 Like