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

Trying to make a gui pop up when a player touches a part? [Solved]

i'm trying to make it so when a player touches a part it enables a players gui.

local Part = script.Parent

Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
            local Player = game.Players:GetPlayerFromCharacter(HIT.Parent)
            Player.PlayerGui.Shop.Frame.Visible = true
    end
end) 

1 answer

✓ Accepted answer

To accommodate for Filtering Enabled, you'll have to use a remote event, because server scripts cannot access existing members of PlayerGui. They may only add new objects to it.

--Server Script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") --this assumes you have the remote here
local part = script.Parent

part.Touched:Connect(function(hit)
	local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if plr then
		remote:FireClient(plr,"") --you can send any information through the second argument, a variant.
	end
end)

--Local Script

local remote = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")
local plr = game:GetService("Players").LocalPlayer

remote.OnClientEvent:Connect(function(args)
	if plr.PlayerGui:FindFirstChild("Shop") then
		plr.PlayerGui.Shop.Frame.Visible = true
	end
end)

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