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

My name changing script is giving an error?

Asked by
Relatch 550 Moderation Voter
9 years ago

I use 2 scripts in this

So, i'm trying to add 1 number to the bot's name after it dies. He starts out as 'Bot1' and I want this script to add 1 to the number each time. This doesn't work because I get the error Workspace.BotArea.Bot1.ExplodeOnDeath:2: attempt to perform arithmetic on global 'botname' (a nil value).

The other problem is that I use a script that doesn't allow the bot to get through the brick. But, the script doesn't work because I check for the name "Bot" in my script, and I don't know how to make it check for the name of the bot.

Here are the two scripts:

c = script.Parent:Clone()
botname = botname + 1

while true do
    wait(0)
    if script.Parent.isDead.Value == true then
        for i = 7,0,-1 do
            script.Parent.Name = "Respawning in "..i.." second(s)."
            wait(1)
        end
        c.Parent = workspace
        c:MakeJoints()
        script.Parent.Name = "Bot"..botname
        script.Parent:Destroy()
    end
end
local SpawnPos=Vector3.new(36.89, 3, -114)

script.Parent.Touched:connect(function(hit)
    if hit.Parent and hit.Parent.Name == "Bot" then
        hit.Parent:MoveTo(SpawnPos)
    end
end)
0
You have to initialize what botname is. You cannot add 1 to a number that hasn't been defined. FearMeIAmLag 1161 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I have edited your script so that it would do what my comment says. I believe this should work, if not, please let me know and I'll try to fix it.

c = script.Parent:Clone()
botname = 1

while true do
    wait(0)
    if script.Parent.isDead.Value == true then
        for i = 7,0,-1 do
            script.Parent.Name = "Respawning in "..i.." second(s)."
            wait(1)
        end
        c.Parent = workspace
        c:MakeJoints()
    botname = botname + 1
        script.Parent.Name = "Bot"..botname
        script.Parent:Destroy()
    end
end

local SpawnPos=Vector3.new(36.89, 3, -114)

script.Parent.Touched:connect(function(hit)
    if hit.Name.sub(1,3) == "Bot" then
        hit.Parent:MoveTo(SpawnPos)
    end
end)

Ad

Answer this question