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

When I respawn a block with this script in it, it doesnt work afterwords. Any thoughts?

For my game I have a pacecar and I scripted this to basically have it so that if you say "green" in the part would turn green but after I respawn the pacecar the script doesnt work, any thoughts on how you would make it work after its been respawned? The code is:

i = 1

function onChatted(msg, recipient, speaker) 

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

if (msg == "yellow") then 
wait(1)
i = 1
while i >= 1 do
	wait(.1)
	script.Parent.BrickColor = BrickColor.New("Black")
	wait(.1)
	script.Parent.BrickColor = BrickColor.New("Bright yellow")
end

end

if (msg == "green") then 
wait(.1)
i = i - 1
script.Parent.BrickColor = BrickColor.New("Lime green")
wait(1)
script.Parent.BrickColor = BrickColor.New("Black")
end 

if (msg == "red") then 
wait(.1)
script.Parent.BrickColor = BrickColor.New("Crimson")
end 

if (msg == "caution off") then 
wait(1)
script.Parent.BrickColor = BrickColor.New("Black")
end 

end 

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

game.Players.ChildAdded:connect(onPlayerEntered)

1 comment

0

Are there any errors?

1 answer

I think what is happening is that after your say the words "yellow", it is stuck on an infinite loop since you are not decreasing the value of i.

i = 1

function onChatted(msg, recipient, speaker) 

	local source = string.lower(speaker.Name)
	msg = string.lower(msg) 
	
	if (msg == "yellow") then 
		wait(1)
		i = 1
		while i >= 1 do --Because "i" is still 1, it will keep runing this piece of code
			wait(.1)
			script.Parent.BrickColor = BrickColor.New("Black")
			wait(.1)
			script.Parent.BrickColor = BrickColor.New("Bright yellow")
		end
	
	end

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