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

Why does this not work?

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)

1 comment

0

2 answers

✓ Accepted answer

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

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