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

How would I fix this error? It references me no matter what

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

0

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

0

Where would I put that though?

0

When you use FindFirstChild

0

Welcome back rhett :)

1 answer

✓ Accepted answer

A long time ago, I use to get this error, that is when I realized my scripts aren't exactly getting the player gui... I wondered for days and more why this happened...???? Then I did a little test, I tried to print a gui name. Nothing happened.. That is when I concluded that you cannot get player gui components from regular scripts... Here is a little rewrite of your code my dude..

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 = script.Parent.Parent.ScreenGUI

            end
    end
    end
    last = tick()
end)

Hopefully this works, I didn't get into seeing what your dex looks like but this will work. All I did was set new crate menu's parent to screen gui, If worked, like accept and upvote m8, ty for reading, baiii

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