So, i recently started making the combat system for my game. First thing i made was the "dashing system" (not really dashing, but the idea behind it is that every time the player presses E, they teleport a few studs forward with any NPCs that are infront of them before the teleport get knocked up and stunned)
Well, first problem i ran into was that the player can teleport not only through walls, but if they are too chonky, they can teleport inside them.
Someone recommended that i use raycasting, which i learned and used in the script below, which of course, still has problems
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local deb = false
player.CharacterAdded:Connect(function(char)
local char = player.Character
local Hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")
UIS.InputBegan:Connect(function(input, gpe)
if gpe then return end
local RayPos = HRP.Position
local RayDirection = HRP.CFrame.LookVector * 50
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {
game.Workspace["Drooling Zombie"],
game.Workspace.Baseplate
}
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.IgnoreWater = true
if input.KeyCode == Enum.KeyCode.E and deb == false then
local ray = workspace:Raycast(RayPos, RayDirection, RayParams)
if ray then
local collision = ray.Position
if collision then
deb = true
Hum.WalkSpeed = 0
Hum.JumpPower = 0
HRP.Anchored = true
task.wait(1)
HRP.Position = collision
task.wait(0.25)
Hum.WalkSpeed = 16
Hum.JumpPower = 50
HRP.Anchored = false
deb = false
elseif not collision then
deb = true
Hum.WalkSpeed = 0
Hum.JumpPower = 0
HRP.Anchored = true
task.wait(1)
HRP.CFrame = HRP.CFrame + (HRP.CFrame.LookVector * 50)
task.wait(0.25)
Hum.WalkSpeed = 16
Hum.JumpPower = 50
HRP.Anchored = false
deb = false
end
end
end
end)
end)
Well, the problem with it is that there are no errors, but, when the ray has collision the HumanoidRootPart gets teleported and it makes the camera all janky because it leaves the rest of the player behind.
Also, even if there are no errors, if the ray has no collision, then the script flat out does not run, at all, even if i have an Elseif statement inside that clearly states that "if there's no collision just do this"
I really need help with this one homies. I appreciate any of it.

1 comment
Thank you, it worked. Man i feel like an idiot now, but either way, this was really helpful. I appreciate it