My screengui will not appear when a part is touched


loads.Enabled = false

function partTouched(obj)
    loads.Enabled = true
end

game.Workspace.fogFAVE.fogfave.Touched:Connect(partTouched)

im trying to make a screengui appear when a player touches a part. in another script, touching the part teleports them to a different game which works fine but the gui wont appear when the part is touched. here is the layout in explorer:

image

Where is the LocalScript located? There’s a chance the code isn’t even running.

forgot to put that part in but its in replicated storage. i tried putting it in the part and putting the ui in startergui before this

just put a print in the script and it isnt running ^

I would put the LocalScript inside of StarterPlayerStarterPlayerScripts personally. Name it however you see fit and put the UI inside of StarterGui.

local part = workspace:WaitForChild("PartNameHere") -- Part that you touch

local localPlayer = game.Players.LocalPlayer
local playerGui = localPlayer:WaitForChild("PlayerGui")
local gui = playerGui:WaitForChild("GuiNameHere") -- Name of the UI you want to become visible

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Humanoid.Health > 0 then
        local char = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(char)
        if player == localPlayer then
            gui.Enabled = true
        end
    end
end)

That’s the pseudocode for how it would function, not entirely sure if it’s bug proof (didn’t test it)

1 Like

okay let me try this, ill tell you if it works

works great tysm!! i was trying to figure this out for a while