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

GUI not showing if a player touches a block?

Ello, I need help with a script that will run if someone touches a block, when someone touches that block a GUI will show up on their screen and only their screen, I am using a local script.

"gui" goes to the GUI that I want to display for that player.

local gui = game.StarterGui.GateGUI.Box
script.Parent.Touched:connect(function(hit)
	local b = hit.Parent:FindFirstChild("Humanoid")
	if b ~= nil then
		gui.Visible = true
	end
	
	
end)

2 answers

✓ Accepted answer

First of all, a local script can only be used by the client and can not be a child of a part. Use a script inside of the block. Second of all, you are trying to make a GUI in starter GUI visible. You would have to reset to make the GUI visible then. Here is the fixed version of the script.

script.Parent.Touched:connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') then
		game.Players[hit.Parent.Name].PlayerGui.GateGUI.Box.Visible = true
	end
end)

This script goes inside the part that will be touched.

StarterGui is loaded into PlayerGui, so changes in StarterGui do not affect PlayerGui after the player joins. Use :GetPlayerFromCharacter(hit.Parent)

script.Parent.Touched:connect(function(hit)
    local b = hit.Parent:FindFirstChild("Humanoid")
    if b ~= nil then
        game.Players:GetPlayerFromCharacter(hit.Parent).GateGui.Visible = true
    end

end)

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