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

PlayerGui is not a valid member of "Workspace" ?

My touched event is supposed to open a gui. At first it opened for everyone when its supposed to open only for the player who touched it. So I edited it and now its broken. Whats wrong?

local UpgradePart = script.Parent

UpgradePart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = hit.Parent.Parent
		player.PlayerGui.UpgradesShop.MainFrame.Visible = true
	else
		return nil
	end
end)

6 comments

1

I already gave you an answer, but basically you should get the player with GetPlayerFromCharacter. Because what you did is get the players Character s Parent , wich is workspace but the PlayerGui isnt in workspace but in the Player intself.

0

true

0

true

0

true

0

true

0

If you teying to make a gui show up when touching a part, I advice you on watching AlvinBlox video talking about it https://youtu.be/6r_PBSXzOmI

3 answers

Try this:

local UpgradePart = script.Parent

UpgradePart.Touched:Connect(function(hit)
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if Player then
		Player.PlayerGui.UpgradesShop.MainFrame.Visible = true
	end
end)

4 comments

0

After the first time you can't open it anymore.

0

Wdym?

0

The first time you step on it, the gui opens. But the second time it doesn't, I hope I explained that well enough

0

Well I would need to see the full project/ code because the script makes it Visible whenever you touch it. So you probably Disable the entire ScreenGui or something in another script /closescript.

You're referencing the player's character, not player, do

local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

PlayerGui is not inside of the character!

try getting the player

local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)

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