i have a script that shows a gui when touched a brick, but I don’t know how to make it appear once, I tried debounce but it repeats for some reason
here’s the one without debounce:
function onTouched(hit)
if hit and hit.Parent then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("ScreenGui") then
local c = v:Clone()
c.Parent = player.PlayerGui
end
end
end
end
end
script.Parent.Touched:Connect(onTouched)
You can easily check if cloned ScreenGui(s) already exists on their PlayerGui if so don’t clone them into their PlayerGui again. If you don’t get what i meant then here is how you would do it:
function onTouched(hit)
if hit and hit.Parent then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for i, v in pairs(script.Parent:GetChildren()) do
if v:IsA("ScreenGui") then
if not player.PlayerGui:FindFirstChild(v.Name) then
local c = v:Clone()
c.Parent = player.PlayerGui
end
end
end
end
end
end
script.Parent.Touched:Connect(onTouched)
Considering they have different names ^
1 Like