script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game.Players.LocalPlayer.PlayerGui.Shop.Frame.Visible = true
end
end)
The Script is inside the part. I know it is not a problem with the gui because i tested it without the part prior.
It works in studio but not in game.
My error I am getting is
Workspace.ShopPart.Script:3: attempt to index field 'LocalPlayer' (a nil value)
i only get it when i test in the start thing.
You are using a Script it appears and not a LocalScript. Experimental Mode was recently removed, and the server can no longer interact with player guis (but this still wouldn't work with experimental mode). The reason this works in Studio is because Play Solo treats the player and client as the same thing.
To fix your issue, you just need to use a LocalScript.
EDIT: Ignore this now, incapaz wrote a better answer, and I forgot to mention LocalScript restrictions.
LocalPlayer
is nil
on the server. You can only use it in LocalScript
s. Use a RemoteEvent
to fire to the client to open the gui. Place a RemoteEvent
and name it something like "OpenShopGui".-- LocalScript under your frame local ReplicatedStorage = game:GetService("ReplicatedStorage") local OpenGui = ReplicatedStorage:WaitForChild("OpenShopGui") OpenGui.OnClientEvent:Connect(function() script.Parent.Visible = true end)
local ReplicatedStorage = game:GetService("ReplicatedStorage") local OpenGui = ReplicatedStorage:WaitForChild("OpenShopGui") script.Parent.Touched:Connect(function(part) -- Switch to :Connect, :connect is deprecated local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent) if plr then OpenGui:FireClient(plr) end end)