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

follow script not working? cant find error. enemy doesnt follow the player.

this script will not make my enemy follow me at all so I didn't ever finish the dmg part cause the follow script was broken any one know the error? the script is in workspace btw EDITED ok so I realized I cant have a string for the enemy because of the script itself so I change the script and still doesn't work but I got a differnent out put too

script

wait(1)
follow = false

while true do
	if game.Players.Player1.Character.Torso ~= nil then
		if game.Players.Player1.Character.Torso.Position - game.Workspace.PotatoMan.Torso.Position.X <= 10 then
			follow = true
		end
	end

if follow then
	game.Workspace.PotatoMan.Humanoid.WalkToPoint = game.Players.Player1.Character.Torso.Position.X
end
	wait(0.5)
end

output

20:49:12.265 - Client(1) Server(0) 20:49:16.108 - Workspace.Script:6: bad argument #2 to '?' (Vector3 expected, got number) 20:49:16.109 - Stack Begin 20:49:16.111 - Script 'Workspace.Script', Line 6 20:49:16.112 - Stack End

3 comments

0

Is there any errors in the output?

0

i dont see any errors but you may the output was 20:33:17.751 - Client(1) Server(0) 20:33:22.397 - Enemy is not a valid member of Workspace 20:33:22.399 - Stack Begin 20:33:22.401 - Script 'Workspace.Script', Line 7 20:33:22.402 - Stack End

0

BlueTaslem you made me just notice the error but it still didnt fix the script for some reason

1 answer

✓ Accepted answer

Because.. at line 06, you did

game.Workspace.PotatoMan.Torso.Position.X <=10

The problem being is,

<=10

If you REALLY can't understand for some reason (the error should've explained it to you just fine), then I'll explain it. It was expecting Vector3, and you gave it a number.

The number is 10. It wasn't expecting that, therefore it doesn't work.

How to fix it: You should be able to fix it already, because I was told not to provide a full answer, but I'll be nice this time.

game.Workspace.PotatoMan.Torso.Position.X <= Vector3.new(10,0,0)

The reason why I did Vector3.new(10,0,0) instead of Vector3.new(0,10,0) or Vector3.new(0,0,10) is because, it's formatted as X,Y,Z. You used Position.X, so I have to use X as well. Now, I hoped I helped, but I can't just give you the answer and go, I recommend using magnitude.

This works very well, and can be planned / sorted on a grid. Region3 works well too, but it seems it would be too complicated for someone who can't solve this error (no offense!).

Here's how magnitude would work:

wait(1)
follow = false

while true do
    if game.Players.Player1.Character.Torso ~= nil then
        if (game.Players.Player1.Character.Torso.Position - 		 game.Workspace.PotatoMan.Torso.Position).magnitude < 10 then
            follow = true
        end
    end

1 comment

1

Hope I helped, I explained it, fixed your script, and recommended a different method. Your very welcome, please tell me if there is anything else you are confused about here :)

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