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

Problem with my bot?

Asked by
Relatch 550 Moderation Voter
9 years ago

My script is supposed to send a bot back to its spawning position when it touches this brick. I set a variable as it's name, so it checks for the bot's name. If it's that name, (Bot), it sends it back to that position. My problem is, I get this error "Workspace.BotArea.InvisibleBlock.BotMove:7: attempt to index global 'model' (a nil value)" and I don't now why. Help?

model = Bot

spawnPos = Vector3.new(36.89, 3, -114)

script.Parent.Touched:connect(function(touched)

    if model:findFirstChild(touched.Name, true) then

        bot.Torso.CFrame = CFrame.new(spawnPos)

    end

end)

2 answers

Log in to vote
1
Answered by 9 years ago

This code checks if the hitter is in workspace.BotArea, then finds which specifically it's in and teleports it.

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

script.Parent.Touched:connect(function(Hit)
    if not Hit then return end
    if Hit:IsDescendantOf(Bots) then
        for _,Bot in pairs(Bots:GetChildren()) do
            if Hit:IsDescendantOf(Bot) then
                Bot:MoveTo(SpawnPos)
                break
            end
        end
    end
end)
Ad
Log in to vote
1
Answered by
LostPast 253 Moderation Voter
9 years ago

Use MoveTo: http://wiki.roblox.com/index.php?title=API:Class/Model/MoveTo

It is way simpler and works better.

Also you never defined what Bot is on line 1. {game.Workspace.Bot?}

Answer this question