I'm trying to make a working shop piece, so that when you touch it, a menu comes up. It works properly and everything, but an error shows up anyway. Here is the script
local last = 0
workspace.Shop.CrateShop.CrateShopTouch.Hitbox.Touched:Connect(function(hit)
if tick() - last <= 1 then
else
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum ~= nil then
if hum then
local player = game.Players:FindFirstChild(hum.Name)
local newCrateMenu = game.ReplicatedStorage.Storage.GUIObjects.CrateShopMenu:Clone()
newCrateMenu.Parent = player.PlayerGui.ScreenGUI
end
end
end
last = tick()
end)
Like I said, the menu comes up and everything, but the error that is made is public, and everyone can see it. Therefore, overtime, anyone with a bad pc will experience quick lag and high ping. I also just want the error to be fixed so I can get this off my list. Here is the error it gives me
****--PlayerGui is not a valid member of Player Stack Begin Script 'Players.rhettsmith6537.PlayerGui.Scripts.ShopTouch', Line 12 Stack End
Anyone know how to fix this error? Also, the error only shows if its someone else other than you hitting the hitbox and it is always YOUR name in there.

4 comments
You're looking for "Humanoid" in the Players service. You should be using GetPlayerFromCharacter(hit.Parent) which will return the player from their character if the "character" is actually a player character
Where would I put that though?
When you use FindFirstChild
Welcome back rhett :)