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?
01 | model = Bot |
02 |
03 | spawnPos = Vector 3. new( 36.89 , 3 , - 114 ) |
04 |
05 | script.Parent.Touched:connect( function (touched) |
06 |
07 | if model:findFirstChild(touched.Name, true ) then |
08 |
09 | bot.Torso.CFrame = CFrame.new(spawnPos) |
10 |
11 | end |
12 |
13 | end ) |
This code checks if the hitter is in workspace.BotArea, then finds which specifically it's in and teleports it.
01 | local SpawnPos = Vector 3. new( 36.89 , 3 , - 114 ) |
02 | local Bots = workspace.BotArea |
03 |
04 | script.Parent.Touched:connect( function (Hit) |
05 | if not Hit then return end |
06 | if Hit:IsDescendantOf(Bots) then |
07 | for _,Bot in pairs (Bots:GetChildren()) do |
08 | if Hit:IsDescendantOf(Bot) then |
09 | Bot:MoveTo(SpawnPos) |
10 | break |
11 | end |
12 | end |
13 | end |
14 | end ) |
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?}