I have tried to make a sliding system with raycasting but there’s a few problems with it, I need a way to constantly detect what part the player is hitting so that the tilt/animations etc can stop, I’ve used run service but I realised it doesn’t constantly update what part you are under, only when you press CTRL (the keybind to slide)
The parts the player can slide on are named “CanSlide”
script.Parent.OnServerEvent:Connect(function(Player,on)
Player.Character.Sliding.Value = on
slidesound.Parent = Character.HumanoidRootPart
slidesound:Play()
slideanim:Play()
local ray = Ray.new(player.Character.HumanoidRootPart.CFrame.p, Vector3.new(0,-10,0), params)
if on then
tiltFunction = game["Run Service"].Heartbeat:Connect(function()
local hit, position, normal = workspace:FindPartOnRay(ray, game.Workspace.Alive)
if hit and hit.Anchored == true and hit.CanCollide == true and hit.Transparency ~= 1 and hit.Name == "CanSlide" then
You should use Raycast, your implementation has been deprecated. You should do this on the client as well. Using run service’s stepped puts you closer to the physics engine.
local raycast_params = RaycastParams.new()
raycast_params.FilterType = Enum.RaycastFilterType.Blacklist
raycast_params.FilterDescendantsInstances = {player_character}
local run_service = game:GetService("RunService")
start_slide_event.Event:Connect(function()
local connection
connection = run_service.Stepped:Connect(function()
local raycastResult = workspace:Raycast(player_character.HumanoidRootPart.Position, Vector3.new(0, -10, 0), raycast_params)
if raycastResult then
if raycastResult.Instance.Name ~= "CanSlide" then
print("Hit not slidable!")
connection:Disconnect()
else
print("Still good!")
end
else
print("Nothing was hit!")
connection:Disconnect()
end
end)
end)
I am pretty sure you can play animation on the character from the client. If not it would still be much better to use this script on the client and fire a remote when it starts and ends to animate.