This is a support category for asking questions about how to get something done on the Roblox websites or how to do something on Roblox applications such as Roblox Studio.
What do you want to achieve?
I want the model to teleport in front of the player, facing the player and play an animation. In this animation, the player will not be able to move.
What is the issue?
Right now, the model teleports in front of the player but it’s not facing the right direction.
What solutions have you tried so far?
I’ve looked a lot and have not found anything, and I’ve tried a couple AI’s to help in this, but it didn’t help much.
Here’s the script I have currently (Monster teleports in front of player, but does not face them):
local monster = workspace.MainMonst
local jumpmonster = workspace.Jumpscare
local function teleportMonsterInFrontOfPlayer(player)
local character = player.Character
if not character then return end
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoidRootPart then return end
local distance = 1
local playerOrientation = humanoidRootPart.CFrame
-- Calculate the new position in front of the player
local newPosition = playerOrientation.Position + (playerOrientation.LookVector * distance)
-- Create a new CFrame for the position and adjust the orientation to face the player
local newCFrame = CFrame.new(newPosition) * CFrame.Angles(0, math.pi, 0)
jumpmonster:SetPrimaryPartCFrame(newCFrame)
monster:SetPrimaryPartCFrame(CFrame.new(game.Workspace.tpmonst.Position))
end
monster.HumanoidRootPart.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
teleportMonsterInFrontOfPlayer(player)
end
end)
in the game I have 2 monsters: One is the monster that actually chases the player (MainMonst) and the jumpscare monster, (Jumpscare). Once the root part of the monster touches the player, the MainMonst gets teleported to a box somwhere else and the jumpscare monster is teleported to the player.