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

how could it be possible to add debounce to this script?

now first of all, i don't really want to send the whole script because it's long and really unnecessary to know, i will attatch the start and the end of the script since the rest isn't really needed. (or so i think)

code samples:

start- (lines 14 to 19)

function onChatted(msg, recipient, speaker) 

local source = string.lower(speaker.Name)
msg = string.lower(msg) 

if (msg == "start") then

end- (lines 127 to 134)

end
end

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

if anyone here could help me out with this (since i'm still relatively new to scripting), i would be overjoyed, thank you!

(edit:) someone asked for the whole thing, so here it is (please no comments about this being inefficient all i want is for it to work

light1 = script.Parent.Light1
light2 = script.Parent.Light2
light3 = script.Parent.Light3
light4 = script.Parent.Light4
light5 = script.Parent.Light5
light6 = script.Parent.Light6
light7 = script.Parent.Light7
light8 = script.Parent.Light8
light9 = script.Parent.Light9
light10 = script.Parent.Light10
sign1 = script.Parent.sign.text.SurfaceGui.TextLabel
local descendants = script.Parent.barriers:GetDescendants()

function onChatted(msg, recipient, speaker) 

local source = string.lower(speaker.Name)
msg = string.lower(msg) 

if (msg == "start") then
	
script.Parent.sign.Part.RaceStart:play()--makes the start sound play (this is where the actual script starts)
sign1.Text = "everybody get ready! (5)"
wait(1)
sign1.Text = "everybody get ready! (4)"
wait(1)
sign1.Text = "everybody get ready! (3)"
wait(1)
sign1.Text = "everybody get ready! (2)"
wait(1)
sign1.Text = "everybody get ready! (1)"
wait(1)
sign1.Text = "everybody get ready! (0)"
wait(1)
sign1.Text = "lights prepared."
wait(2)

--------------------------------------------------------------------
-- Loop through all of the descendants of the Workspace. If a
-- BasePart is found, the code changes that parts color to green
for index, descendant in pairs(descendants) do
	if descendant:IsA("BasePart") then
		descendant.CanCollide = true
	end
end
--------------------------------------------------------------------
wait(1)

script.Parent.sign.Part.Sound2:play()--makes the start sound play
light1.Transparency = 0
sign1.Text = "5"
wait(1)
light2.Transparency = 0
sign1.Text = "4"
wait(1)
script.Parent.sign.Part.Sound2:stop()--makes the start sound stop
script.Parent.sign.Part.Sound:play()--makes the start sound play
light3.Transparency = 0
sign1.Text = "3"
wait(1)
light4.Transparency = 0
sign1.Text = "2"
wait(1)
light5.Transparency = 0
sign1.Text = "1"
wait(1)
light1.BrickColor = BrickColor.new("Lime green")
light2.BrickColor = BrickColor.new("Lime green")
light3.BrickColor = BrickColor.new("Lime green")
light4.BrickColor = BrickColor.new("Lime green")
light5.BrickColor = BrickColor.new("Lime green")
sign1.Text = "GO!"
--------
-- Loop through all of the descendants of the Workspace. If a
-- BasePart is found, the code changes that parts color to green
for index, descendant in pairs(descendants) do
	if descendant:IsA("BasePart") then
		descendant.CanCollide = false
	end
end
--------
wait(5)
light1.BrickColor = BrickColor.new("Really red")
light2.BrickColor = BrickColor.new("Really red")
light3.BrickColor = BrickColor.new("Really red")
light4.BrickColor = BrickColor.new("Really red")
light5.BrickColor = BrickColor.new("Really red")
sign1.Text = "restarting..." -- do a funky lights sequence because it looks cool
light1.Transparency = 0
light2.Transparency = 1
light3.Transparency = 1
light4.Transparency = 1
light5.Transparency = 0
wait(.5)
light1.Transparency = 1
light2.Transparency = 0
light3.Transparency = 1
light4.Transparency = 0
light5.Transparency = 1
wait(.5)
light1.Transparency = 1
light2.Transparency = 1
light3.Transparency = 0
light4.Transparency = 1
light5.Transparency = 1
wait(.5)
light1.Transparency = 1
light2.Transparency = 0
light3.Transparency = 1
light4.Transparency = 0
light5.Transparency = 1
wait(.5)
light1.Transparency = 0
light2.Transparency = 1
light3.Transparency = 1
light4.Transparency = 1
light5.Transparency = 0
wait(.5)
light1.Transparency = 1
light2.Transparency = 1
light3.Transparency = 1
light4.Transparency = 1
light5.Transparency = 1
sign1.Text = "restart successful!" -- tell the player that the game isnt dead
wait(2)
sign1.Text = "sample text" -- reset the text to the funny sample text

end
end

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

3 comments

0

Can you give all of it?

0

what's the purpose of the script? Could you elaborate?

0

i attatched the full script, it's for starting lights at the circuit that i'm making

1 answer

✓ Accepted answer
light1 = script.Parent.Light1
light2 = script.Parent.Light2
light3 = script.Parent.Light3
light4 = script.Parent.Light4
light5 = script.Parent.Light5
light6 = script.Parent.Light6
light7 = script.Parent.Light7
light8 = script.Parent.Light8
light9 = script.Parent.Light9
light10 = script.Parent.Light10
sign1 = script.Parent.sign.text.SurfaceGui.TextLabel
local descendants = script.Parent.barriers:GetDescendants()
local debounce = false

function onChatted(msg, recipient, speaker) 

local source = string.lower(speaker.Name)
msg = string.lower(msg) 

if (msg == "start") then
local debounce = true
script.Parent.sign.Part.RaceStart:play()--makes the start sound play (this is where the actual script starts)
sign1.Text = "everybody get ready! (5)"
wait(1)
sign1.Text = "everybody get ready! (4)"
wait(1)
sign1.Text = "everybody get ready! (3)"
wait(1)
sign1.Text = "everybody get ready! (2)"
wait(1)
sign1.Text = "everybody get ready! (1)"
wait(1)
sign1.Text = "everybody get ready! (0)"
wait(1)
sign1.Text = "lights prepared."
wait(2)

--------------------------------------------------------------------
-- Loop through all of the descendants of the Workspace. If a
-- BasePart is found, the code changes that parts color to green
for index, descendant in pairs(descendants) do
    if descendant:IsA("BasePart") then
        descendant.CanCollide = true
    end
end
--------------------------------------------------------------------
wait(1)

script.Parent.sign.Part.Sound2:play()--makes the start sound play
light1.Transparency = 0
sign1.Text = "5"
wait(1)
light2.Transparency = 0
sign1.Text = "4"
wait(1)
script.Parent.sign.Part.Sound2:stop()--makes the start sound stop
script.Parent.sign.Part.Sound:play()--makes the start sound play
light3.Transparency = 0
sign1.Text = "3"
wait(1)
light4.Transparency = 0
sign1.Text = "2"
wait(1)
light5.Transparency = 0
sign1.Text = "1"
wait(1)
light1.BrickColor = BrickColor.new("Lime green")
light2.BrickColor = BrickColor.new("Lime green")
light3.BrickColor = BrickColor.new("Lime green")
light4.BrickColor = BrickColor.new("Lime green")
light5.BrickColor = BrickColor.new("Lime green")
sign1.Text = "GO!"
--------
-- Loop through all of the descendants of the Workspace. If a
-- BasePart is found, the code changes that parts color to green
for index, descendant in pairs(descendants) do
    if descendant:IsA("BasePart") then
        descendant.CanCollide = false
    end
end
--------
wait(5)
light1.BrickColor = BrickColor.new("Really red")
light2.BrickColor = BrickColor.new("Really red")
light3.BrickColor = BrickColor.new("Really red")
light4.BrickColor = BrickColor.new("Really red")
light5.BrickColor = BrickColor.new("Really red")
sign1.Text = "restarting..." -- do a funky lights sequence because it looks cool
light1.Transparency = 0
light2.Transparency = 1
light3.Transparency = 1
light4.Transparency = 1
light5.Transparency = 0
wait(.5)
light1.Transparency = 1
light2.Transparency = 0
light3.Transparency = 1
light4.Transparency = 0
light5.Transparency = 1
wait(.5)
light1.Transparency = 1
light2.Transparency = 1
light3.Transparency = 0
light4.Transparency = 1
light5.Transparency = 1
wait(.5)
light1.Transparency = 1
light2.Transparency = 0
light3.Transparency = 1
light4.Transparency = 0
light5.Transparency = 1
wait(.5)
light1.Transparency = 0
light2.Transparency = 1
light3.Transparency = 1
light4.Transparency = 1
light5.Transparency = 0
wait(.5)
light1.Transparency = 1
light2.Transparency = 1
light3.Transparency = 1
light4.Transparency = 1
light5.Transparency = 1
sign1.Text = "restart successful!" -- tell the player that the game isnt dead
wait(2)
sign1.Text = "sample text" -- reset the text to the funny sample text
wait(10) -- 10 seconds where u cant use script
local debounce = false
end
end

function onPlayerEntered(newPlayer) 
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end) 
end 

game.Players.ChildAdded:connect(onPlayerEntered)

4 comments

0

tell me if the debounce works, you can change the wait(10) at the bottom to whatever you want

0

hold on, this isn't related to the debounce at all, but the script doesn't work for whatever reason

0

apparently, roblox broke the script i think

0

since roblox adds a blank character after every text input now, i'm going to adjust the script and then test it

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