Ad
Log in to vote
0

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

Asked by 4 months ago

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)
0
Are there any errors? skate992 21 — 4mo

1 answer

Log in to vote
0
Answered by 4 months ago

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
Ad

Answer this question