Teleportation Ability Keeps Erroring?

Alright so, I’m trying to make it so that whenever the player presses Z with another movement key (W, A, S, or D) then they will teleport in that direction but for some reason whenever I test the S key, it just straight up errors?

local TeleportEvent = script:WaitForChild("TeleportFunction")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")

UserInputService.InputBegan:Connect(function(input, processed)
	if processed then return end
	if not processed and LocalPlayer.Name == "dzhann757" then
		if input.KeyCode == Enum.KeyCode.Z then
			local DashDirection = "Front"

			if UserInputService:IsKeyDown(Enum.KeyCode.S) then
				DashDirection = "Back"

			elseif UserInputService:IsKeyDown(Enum.KeyCode.A) then
				DashDirection = "Left"

			elseif UserInputService:IsKeyDown(Enum.KeyCode.D) then
				DashDirection = "Right"
			end
			
			TeleportEvent:Invoke(DashDirection, HRP)
		end
	end
end) -- This is the script for the W, A, S, and D keys.
local DashFunction = script.Parent

DashFunction.OnInvoke = function(Direction, Root)
	if Direction == "Front" then
		Root.Parent:MoveTo(Root.Position + Root.CFrame.LookVector * 50)
	elseif Direction == "Back" then
		Root.Parent:MoveTo(Root.Positon - Root.CFrame.LookVector * 50)
	end
end -- This is the script for teleporting after processing the first script.

Can anyone also suggest what to write for the A and D key? (left and right) It’s almost complete.

2 Likes

Post the error message and which line(s) it points to.

2 Likes

me when the code is too long and not a 3 line code that uses a touch function only

Screenshot 2024-11-09 055819

also this part you can just switch :MoveTo into .Position since we arent moving the entire model and instead only the rootpart which will also move the entire body with it. if theres other error codes then let me know :grinning:


Here’s the error message!

It’s just a typo. You wrote Root.Positon, it should be Root.Position.

1 Like

It’s Position, not Positon. You missing an i there lol :slight_smile:

1 Like

Dang, I completely forgot to check my spelling :C

Also uhhh how do u write the script for A and D key? The teleportation script is almost complete :smiley:

wdym, the A and D don’t work? I mean how?
You should use Character:PivotTo() instead btw

1 Like

No, it’s not that the A and D don’t work. It’s that I don’t know how to write the lines for A and D.

ah I see.
Utilize the RightVector instead and for left do RightVector * -50 if I’m sure (maybe)

Does the Left Vector even exist lol

No it doesn’t, but you can negate RightVector 50 degs backwards (so left) to make it tp left.

Wait, how do you even do that? I’ve never heard of it.

ok so maybe this works???>>>:

	if Direction == "Right" then
		Root.Parent:MoveTo(Root.Position + Root.CFrame.RightVector * 50)
	elseif Direction == "Left" then
		Root.Parent:MoveTo(Root.Positon + Root.CFrame.RightVector * -50)
1 Like

By the way, should read more about other things on CFrames, like:

1 Like

Oh it works! Thank You for the help! :smiley:

1 Like

Oh okay. I will definitely look at those :smiley:

1 Like

Also if you trying to keep exploits away, should add checks def. like cooldown and like relying more on the player instance rather than the client sending params which could be false who knows :wave:

tbh I really don’t add exploit checks that much because this is a like just a small little project and it’s gonna be not really a game but will DEFINITELY note that! :smiley:

1 Like

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