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

How do I make my shop opening script work when a player touches a part?

I added a ring into the workspace and placed it in front of my shop model and scripted it so that when a person touches the ring, the shop GUI would appear. I then added a local script into StarterPlayerScripts and typed the script below. But when I tested it out, the Shop GUI wouldn't open and there was no error on the output. I do not know what is happening. Where is the error or thing that I should update on my script?

Script:

local ShopRing = game.Workspace.ShopRing

ShopRing.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then

		local ShopGUI = game.StarterGui.ShopGuiScreen.ShopFrame
		ShopGUI.Visible = true
	
	end
end)

1 comment

0

You need to get the GUI from the player's PlayerGui, not StarterGui.

3 answers

Use GetPlayerFromCharacter from the hit.Parent and then you can do player.PlayerGui not StarterGui.

local Players = game:GetService("Players")
local plr =  Players:GetPlayerFromCharacter(hit.Parent)

1 comment

0

Also I belive you should have a server script in the Model.

Try this, it might work.

Script:

local ShopRing = game.Workspace.ShopRing     
local ShopGUI = game.StarterGui.ShopGuiScreen.ShopFrame 

 ShopRing.Touched:Connect(function(hit)

     if game.Players:FindFirstChild(hit.Parent).PlayerGui then    
         if game.Players:FindFirstChild("ShopGui') then      
            print("Player have a Gui!")       
         else                                                                                                     
             wait(2) 
             ShopGui.Parent = game.Players:FindFirstChild(hit.Parent).PlayerGui
             local CloneShop = ShopGUI:Clone()   
             CloneShop.Parent = game.StarterGui                          
             CloneShop.Visible = false                               
         end
  end)

you need to change the PlayerGui:

local ShopRing = game.Workspace.ShopRing

ShopRing.Touched:Connect(function(hit)

    if hit.Parent:FindFirstChild("Humanoid") then
	local plr = game.Player:FindFirstChild(hit.Parent)
	
	plr.PlayerGui.StarterGui.ShopGuiScreen.ShopFrame.Visible = true
	
    

    end
end)

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