Unable to make shop GUI appear

So, I am trying to make this cookie clicker game and i have come across an issue
that i have somehow not been able to fix for a while now. The issue is that I am
trying to make the gui become visible when the player touches a part but i cannot
seem to get it to work. Ive looked at many different dev forum posts and even tried to copy and paste the Developer Documentation scripts. I have also tried to alter the cantouch checkbox. This is the script that I ended up with:

ShopTouch = script.Parent

ShopTouch.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		print("yes")
		game.StarterGui.Shop.Frame.Visible = true
		
	end
end)

game.StarterGui is a container for all the UI’s which replicates to the Player’s PlayerGui. You’d need to get the player’s Player Instance from hit, then index through to Player.PlayerGui.Shop.Frame.

For example,

ShopTouch = script.Parent
local Players = game:GetService("Players")

ShopTouch.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if not player then return end
    local PlayerGui = player.PlayerGui
    PlayerGui.Shop.Frame.Visible = true
end)
3 Likes

That doesn’t work as the StartGui is, as in the name, the starting Gui each New player gets when they leave or join. Try this?

game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui.Frame.Visible = true

Somehow im having the same problem, is the local script meant to be somewhere other than inside the text button?

The problem i had was that the script was inside the part and not inside the StarterGui

Local scripts cannot work inside workspace . Instead you need to put a local script inside StarterGui, Or StarterPlayer. So using a local script in one of these locations and changing the route of the touching part should work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.