How can I fix this? I have a script that once a player steps on a Part, it opens a GUI but, it only opens once. I have a localscript that fires an event which adds coins to the players inventory, but, the GUI only appears once, how do I change that so whenever they step on the part and the collected value is false, it opens how do I do this?
local guiname = "RewardGUI" script.Parent.Touched:connect(function(hit) if hit == nil then return end if hit.Parent == nil then return end local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player ~= nil and player.collected.Value == false then if player:FindFirstChild("PlayerGui") then if not player.PlayerGui:FindFirstChild(guiname) then local ui = script.Parent:FindFirstChild(guiname):clone() ui.Parent = player.PlayerGui end end end end)
You didn't destroy the GUI, you just add it and done, and if the localscript deletes it you have to do it in a script because localscripts changes like destroy are not replicated because of FilteringEnabled, also if you don't delete it it won't work because in the line 10 you are checking if the gui is there, Hope it works! :D
local guiname = "RewardGUI" script.Parent.Touched:connect(function(hit) if hit == nil then return end if hit.Parent == nil then return end local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player ~= nil and player.collected.Value == false then if player:FindFirstChild("PlayerGui") then if not player.PlayerGui:FindFirstChild(guiname) then local ui = script.Parent:FindFirstChild(guiname):clone() ui.Parent = player.PlayerGui wait(2) -- change it for delay ui:Destroy() end end end end)
You could just use the .enabled property and set it to true/false to whether it comes up. That's what I use to make the guis pop up and off.