Teleport behind player move not working

Wassup! I’m trying to make Sonic.EXE for a project of mine, and one of his moves is he disappears into fog and teleports behind the player. However, that is not working for me. It just teleports me slightly to my right/left

I have tried looking around for fixes, but to no avail.

Code:

		teleport_exe.OnServerEvent:Connect(function(player)
			local character = player.Character
			if not character then return end
			local humanoid_root = character:WaitForChild("HumanoidRootPart")
			local humanoid = character:WaitForChild("Humanoid")
			local fog = game.ServerStorage.STORAGE.PARTICLES.FOG_PARTICLE:Clone()
			fog.Parent = humanoid_root
			DEBRIS:AddItem(fog, 8)
			
			local ray_params = RaycastParams.new()
			ray_params.FilterType = Enum.RaycastFilterType.Blacklist
			ray_params.FilterDescendantsInstances = {character}
			
			local origin = humanoid_root.Position
			local direction = humanoid_root.CFrame.LookVector * 1000
			
			local raycast_result = workspace:Raycast(origin, direction)
			
			if raycast_result and game.Players:GetPlayerFromCharacter(raycast_result.Instance.Parent) then
				fog:Emit(40)
				local other_hrp:BasePart = raycast_result.Instance.Parent.HumanoidRootPart
				
				humanoid_root.CFrame = other_hrp.CFrame + Vector3.new(-3,0,0)
			end
		end)

Any help will be appreciated :cowboy_hat_face:

1 Like

Use LookVector to get the direction that the player is looking, then convert that to a unit and multiply that by negative 3 :slight_smile:

humanoid_root.CFrame = other_hrp.CFrame + other_hrp.CFrame.LookVector.Unit * -3
3 Likes

This isn’t working for me. It moves me backwards, and even when I make it just normal 3 instead of -3, it only moves me up by 3 studs.

Hold on, try changing it to just LookVector, my bad. It should work just fine like that.

humanoid_root.CFrame = other_hrp.CFrame + other_hrp.CFrame.LookVector * -3

(Sorry, I haven’t worked with this in a while)

3 Likes

For some odd reason, it’s still not working.

Video:

I believe it targets your own character.

Edit: I said to add a blacklist filter and removed that because I saw that you had one, but I now realize that you just didn’t add the ray params to your raycast so I was correct lol.

2 Likes

Thank you so much! However, while it isn’t targeting my player, it also isn’t targeting other players.

Video:

You have it set to only target Players.

2 Likes

What do you mean by ‘Target Players’? (I think i need chars im not coutning tho so i’ll add this)

1 Like

Sorry for the late reply, but you check whether or not the potential target is a player by making

this a condition. And since this is a condition and those are assumably dummies, this will not work with them.

2 Likes

Thank you so much! This helps me out alot :smile:

1 Like

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