The main issue is that Randomplayer is the Player object whcih is not the Players position. As you are getting a list of player at the start of the script it may also cause issue if a player leaves the game.
To avoid this I would put it all in the PickPlayer function
local plrServ = game:GetService('Players')
local function PlayerPicker()
local Players = plrServ:GetPlayers()
if #Players > 0 then
local RandomPlayer = Players[math.random(1, #Players)]
if RandomPlayer.Character then
RandomPlayer.Character.Torso.CFrame
end
end
end
Now that you have the players position we can work out what is "back" from the charactes CFrame. We can work in object space (this is outside the scope of this question please reaserch this if you do not know what it is)
local function TpToPlayer()
local teleportTo = PlayerPicker() * CFrame.new(0,0, -10)
MonsterTorso.CFrame = teleportTo
end
You may find that using CFrame will teleport the monster into object in which case you would want to use Position as it will then teleport the monster on top of object.
I hope this helps. Please comment if you have any other questions about this post.
2 comments
10 studs in what direction? infront behind
Behind