Positions={CFrame.new(135.051, 40.7, -27.949),CFrame.new(135.051, 40.7, -42.949),CFrame.new(135.051, 40.7, -61.949)} MovePlayer=function(player) for p=1,#Positions do player.Character.Torso.CFrame=Positions[p] end PlayerEnter=function(player) -- Bunch of irrelevant functions here player.Changed:connect(function(prop) if (prop=="Character") then MovePlayer(player) end end) end
It's not moving the player's torso. Also, is there any way I could make the points random? I feel like if the script did work, Positions[p] would just set the move point to a same position each time.
Thank you in advance!
First, fix the blatant style problems.
Use standard function declaration syntax:
function name() -- body end
Tab your code, and put spaces around operators! It makes it easier to read! Remove clutter!
function MovePlayer(player) for p = 1, #Positions do player.Character.Torso.CFrame = Positions[p] end -- FUNCTION MISSING END
Use generic for
loops:
function MovePlayer(player) for _, position in ipairs(Positions) do player.Character.Torso.CFrame = position end end
Use the standard events. There's a CharacterAdded
event -- don't use Changed
.
function PlayerEnter(player) -- Bunch of irrelevant functions here player.CharacterAdded:connect(MovePlayer) end
Now, this should work. However, MovePlayer
will essentially only care about the last thing in the list:
n = 5 n = 4 n = 9 n = 3
Does the same thing as simply
n = 3
Which is all the loop is doing. If you were to add a wait
, you would see the player appear at each point, then move to the next.
I'm guessing you want to pick a random point from the list.
function MovePlayer(character) character:WaitForChild("Torso").CFrame = Positions[math.random(#Positions)] end