Hello! Decently new scripter here. I’m trying to follow along with a tutorial that shows how to create a sliding system with RaycastHitboxV4, but I’ve gotten into a few hiccups.
- The hitboxes for the rays are not attaching to my character’s feet
- My slide animation isn’t loading when I hit Q (my keybind)
- Print statements are not printing in the output
-
I’m consistently getting this error when playtesting. It leads back to the script that creates Signals.
Here is my code. If anyone could help me I would be extremely thankful. I can also supply the code in my module scripts if need be.
OnSlide
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local Promise = require(ReplicatedStorage.Modules.Promise)
local RaycastModule = require(ReplicatedStorage.Modules.RaycastHitboxV4)
local plr = game.Players.LocalPlayer
local playerConfig = require(plr.PlayerScripts:WaitForChild("PlayerModule"))
local ctrls = playerConfig:GetControls()
local char = script.parent
local hrp = char:WaitForChild("HumanoidRootPart")
local slideHitboxModel = plr.Backpack.SlideHitboxes
local slideHitbox = RaycastModule.new(slideHitboxModel)
slideHitbox.DetectionMode = RaycastModule.DetectionMode.PartMode
slideHitbox.Visualizer = true
slideHitbox.RayDirection = Vector3.new(0, -0.6, 0.3)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {plr.Character}
params.FilterType = Enum.RaycastFilterType.Blacklist
params.IgnoreWater = true
slideHitbox.RaycastParams = params
local slidingAttachment = Instance.new("Attachment")
slidingAttachment.Name = "SlidingAttachment"
slidingAttachment.Parent = hrp
local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.Enabled = false
alignOrientation.RigidityEnabled = true
alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
alignOrientation.Attachment0 = slidingAttachment
alignOrientation.Parent = hrp
local animator = plr.Character.Humanoid:WaitForChild("Animator")
local slidingAnim = ReplicatedStorage.Assets.Animations.Slide
local slideAccel = 32
function onSlideKeyPressed(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
doSlide()
end
end
ContextActionService:BindAction("SLIDE_ACTION", onSlideKeyPressed, true, Enum.KeyCode.Q)
function doSlide()
ReplicatedStorage.Remotes.AttachSlideHitbox:InvokeServer()
local isInSlideMode = false
local postMovementEvent
local onHitEv
local floorNormal
local slidingAnimTrack = animator:LoadAnimation(slidingAnim)
local timeSinceSlideStart = 0
local function reset()
if onHitEv then
onHitEv:Disconnect()
end
if postMovementEvent then
postMovementEvent:Disconnect()
end
ctrls:Enable()
slidingAnimTrack:Stop()
slideHitbox:HitStop()
hrp.AssemblyLinearVelocity = Vector3.zero
alignOrientation.Enabled = false
char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
onHitEv = slideHitbox.OnHit:Connect(function(part, _, raycastResult)
slideHitbox:HitStart()
floorNormal = raycastResult.Normal
local slopeVector = hrp.CFrame.RightVector:Cross(floorNormal).y
if slopeVector >= 0.1 then
if isInSlideMode then
print("Stopped slide: Slope too steep!")
reset()
end
return
end
if not isInSlideMode then
print("In slide mode")
isInSlideMode = true
alignOrientation.Enabled = true
hrp.AssemblyLinearVelocity = Vector3.zero
char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
ctrls:Disable()
slidingAnimTrack.Looped = true
slidingAnimTrack:Play()
local forwardForce = slopeVector.Unit + hrp.AssemblyMass + slideAccel
hrp:ApplyImpulse(forwardForce)
slideHitbox.onHitNothing:Connect(function()
floorNormal = nil
end)
postMovementEvent = game:GetService("RunService").Heartbeat:Connect(function(dt)
timeSinceSlideStart *= dt
local linearVelocity = hrp.AssemblyLinearVelocity
hrp.AssemblyLinearVelocity = linearVelocity - floorNormal * linearVelocity:Dot(floorNormal)
alignOrientation.CFrame = CFrame.lookAt(Vector3.Zero, hrp.AssemblyLinearVelocity)
if timeSinceSlideStart >= 0.2 then
if ((hrp.AssemblyLinearVelocity * Vector3.new(1, 0, 1)).Magnitude < 0.1) then
print("Stopped slide: Reached 0 Velocity")
reset()
return
end
end
end)
end
end)
slideHitbox:HitStart()
game:GetService("RunService").Heartbeat:Wait()
game:GetService("RunService").Heartbeat:Wait()
if not isInSlideMode then
if onHitEv then
onHitEv:Disconnect()
--not on the ground so exit then
end
print("Stopped slide: Not on valid ground")
end
end