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.
me when the code is too long and not a 3 line code that uses a touch function only
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
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)
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
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!