Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does this not work?

Asked by 8 years ago

Hi! So, I just started with this script (I've been playing around with different stuff for a bit) so I tried to make this script where if you stepped on it it would create a ScreenGui and place it in StarterGui. It does just that, however it will keep doing it each time I step on it. How do I make it only do it once?

function kill(part)
    local sc = Instance.new("ScreenGui", game.StarterGui) 
    end
script.Parent.Touched:connect(kill)
0
Take a look at this link: http://wiki.roblox.com/index.php?title=Debounce DigitalVeer 1473 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

Hallo, laffydecious. Der beste Weg, dies zu tun wäre, um zu überprüfen, ob die ScreenGui ist bereits in StarterGui, werde ich einige Beispiel-Code unten bieten.

function kill(part)
    if not game.StarterGui:FindFirstChild('MyGUI') then
        local sg = Instance.new("ScreenGui", game.StarterGui) 
        sg.Name = 'MyGUI'
    end
end

script.Parent.Touched:connect(kill)
Ad
Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
8 years ago
local touched = false

function kill(part)
    if not touched then -- checks if touched is false
        touched = true -- makes touched true meaning it wont run this code again unless touched is changed to false
        local sc = Instance.new("ScreenGui", game.StarterGui) 
    end
end

script.Parent.Touched:connect(kill)

Answer this question