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

Why does my GUI not pop up or animate when I touch a part?

Hello, I'm helping someone make their game and I am trying to do the GUI aspect of it.

They told me to make a shop, which I am doing. So what I am trying to do is, when you walk on the part, the GUI will either popup, or slide in. However, when I tried to do either of these, none of them worked, and nothing came in the output and I am not sure what is wrong. Can someone help me?

--Variables
local shop = game.Players.LocalPlayer.PlayerGui.ScreenGui.Background
local part = script.Parent

--main

	 part.Touched:Connect(function(hit)
	  if hit.Parent:FindFirstChild("Humanoid") then
	   game.Players.LocalPlayer.PlayerGui.ScreenGui.Background.Visible = true
	  end
	 end)

and

--Variables
local shop = game.Players.LocalPlayer.PlayerGui.ScreenGui.Background
local part = script.Parent


part.Touched:Connect(function(hit)
	  if hit.Parent:FindFirstChild("Humanoid") then
	shop:TweenPosition(UDim2.new(0.5, -125,1.502, 0))
		end
	end)

Both of these scripts were not executed at the same time. They were executed one at a time and they didn't work.

They were Scripts inside the part that was supposed to be touched by the player and they were the normal script. Can someone tell me where I have gone wrong?

2 comments

0

On Line 2 with the shop Variable, use "WaitForChild()" for the player Gui and the screen Gui posibly because not all roblox assets are loaded.

0

@Tizzel40 This isn't a local script... And the gui would open even with no assets loaded

1 answer

✓ Accepted answer

Hello, tonyv537!

As this is a normal script on a part, Local Player isn't defined, so you must grab the player from the character you identified when touching....

--Variables
--  Local player don't exists on a normal script
local part = script.Parent


part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		shop = game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.SreenGui.Background -- "game.Players:GetPlayerFromCharacter(hit.Parent)" grabs the player using the character reference
		shop:TweenPosition(UDim2.new(0.5, -125,1.502, 0))
        end
end)

Good Luck with your games

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