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

(Solved!) Infinite Yield for making a GUI visible on touch?

When I step on the part it has a infinite yield for the gui shop to turn visible can someone help?

I believe everything is right with the script but it's probably not I probably made a small error.

Here's the script!

script.Parent.Touched:Connect(function(hit)
	local char = hit.Parent
	local playerName = char.Name
	local player = game.Players[playerName]
	local shop = player.PlayerGui:WaitForChild("Shop")
	
	shop.ChooseShop.Visible = true
end)

script.Parent.TouchEnded:Connect(function(hitEnd)
	local char = hitEnd.Parent
	local playerName = char.Name
	local player = game.Players[playerName]
	local shop = player.PlayerGui:WaitForChild("Shop")
	
	shop.ChooseShop.Visible = false
end)

3 comments

0

You cannot access any gui from server

0

just clone the gui from replicated storage or something to the playergui

0

The .Touched and .TouchEnded can also spam hundreds of touched and touchended events unless you use a debounce

1 answer

✓ Accepted answer

A script can't access a PlayerGui's descendants so I would recommend u use a :Clone() and :Destroy() like this . You need to parent the shop gui inside the script.

script.Parent.Touched:Connect(function(hit)
    local char = hit.Parent
    local playerName = char.Name
    local player = game.Players[playerName]
    shop = script.Shop--You need to put the shop gui as a child of the script
    shop.Parent = plr.PlayerGui
    shop.ChooseShop.Visible = true
end)

script.Parent.TouchEnded:Connect(function(hitEnd)
    local char = hitEnd.Parent
    local playerName = char.Name
    local player = game.Players[playerName]
    shop:Destroy()
end)

1 comment

0

id recommend using a remote event to find the gui rather than this method. but w/e u want

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