Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GUI not showing if a player touches a block?

Asked by 6 years ago

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

Log in to vote
0
Answered by
4D_X 118
6 years ago

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.

Ad
Log in to vote
0
Answered by
GingeyLol 338 Moderation Voter
6 years ago

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)

Answer this question