Hey guys, so I have made this script so when you touch it a Gui appears, but it seems it doesn't work for some reason? please help.
local Buying = game.StarterGui.Buying.Frame
script.Parent.Touched:connect(function(otherPart)
Buying.Visible = true
end)
local Players = game:GetService('Players') -- Getservice get's the Players from gameservice even if Players had a different name script.Parent.Touched:connect(function(hit) -- when Touched if Players:FindFirstChild(hit.Parent.Name) then -- Finds hit.Parent.Name which should be the player local plr = Players:FindFirstChild(hit.Parent.Name) -- defines the player plr.PlayerGui.Buying.Visible = true -- Gets the PlayerGui from players and changes Buying to visible end end)
This is because you are using deprecated code, not using a remote event, and using StarterGUI when you use PlayerGUI. You can’t access the PlayerGui from the server and shouldn’t be.
--LocalScript under StarterGui/PlayerGui local remote = Instance.new('RemoteEvent') remote.Name = 'ShowGui' remote.Parent = game:GetService'ReplicatedStorage' local plr = game:GetService('Players').LocalPlayer local pgui = plr:WaitForChild'PlayerGui' local gui = game:GetService('ReplicatedStorage').Buying --put the gui in replicated remote.OnClientEvent:Connect(function(enabled) if not pgui:FindFirstChild(gui.Name) then -- so we don’t overflow and lag our player gui:Clone().Parent = pgui --cloning our gui into Playergui, not startergui!! gui.Frame.Visible = enabled --set visibility end end)
.
-- Server script under the part local plrs = game:GetService'Players' local rep = game:GetService'ReplicatedStorage' script.Parent.Touched:Connect(function(part) --connect is deprecated. use Connect local plr = plrs:GetPlayerFromCharacter(part.Parent) if plr then rep.ShowGui:FireClient(plr, true) -- fire remote to client end end)