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)
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.