Function teleports the player correctly once, then will stay only on the first tp spot

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to teleport the player 5 studs in front of them every time the remote event is activated

  2. What is the issue? Include screenshots / videos if possible!
    Local variables in function not changing(?) It only teleports the player slightly off the first teleport after the first activation
    robloxapp-20240806-1939242.wmv (1005.0 KB)

here is the script

-- local remoteEvent = game.ReplicatedStorage.RemoteEvent

remoteEvent.OnServerEvent:Connect(function()
	local HumanoidRootPart = Tool.Parent.HumanoidRootPart
	local Direction = HumanoidRootPart.Parent.Head.CFrame.LookVector
	local Distance = 5
	local Target = HumanoidRootPart.Parent.Head.CFrame.Position + (Direction * Distance)
	print(Target)
	local AnimTrack = Tool.Parent:WaitForChild("Humanoid"):LoadAnimation(anim[1])
	
	HumanoidRootPart.Position = Target
end)

i just come back to scripting after a long time and im stumped

Try to use this code:

-- See if you have a RemoteEvent named "RemoteEvent" in ReplicatedStorage
local remoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")

remoteEvent.OnServerEvent:Connect(function(player)
    local character = player.Character
    if character then
        local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
        if humanoidRootPart then
            local direction = humanoidRootPart.CFrame.LookVector
            local distance = 5
            local targetPosition = humanoidRootPart.Position + (direction * distance)
            
            humanoidRootPart.CFrame = CFrame.new(targetPosition)
        end
    end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.