Slide script weird movement glitch

I am trying to make an fps game (a simple test one) that has a slide script but when the player slides the other clients and the server see the player in weird places like inside walls the code is

local event = game.ReplicatedStorage.Slide
local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)

event.OnServerEvent:Connect(function(plr, camCFrame)

	local SlideDistance = plr.Character.SlideDistance.Value

	local char = plr.Character
	local isSliding = false
	local isOnSlope = false

	local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0, -1, 0) * 10)
	local hit, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, char:GetDescendants())
	if hit and normal.Y < 0.95 then
		isOnSlope = true
	end

	if char.Humanoid.FloorMaterial ~= Enum.Material.Air and not isSliding and (SlideDistance > 0 or isOnSlope) then

		local lookVector = Vector3.new(camCFrame.LookVector.X, 0, camCFrame.LookVector.Z).Unit

		if isOnSlope then

			local rightVector = lookVector:Cross(normal)
			if normal.Y > 0 then

				lookVector = rightVector:Cross(-normal).Unit
			else

				lookVector = rightVector:Cross(normal).Unit
			end
			SlideDistance = SlideDistance * normal.Magnitude
		end

		local myRay = Ray.new(char.HumanoidRootPart.Position, lookVector * SlideDistance)
		local hit, position = workspace:FindPartOnRayWithIgnoreList(myRay, char:GetDescendants())
		local newPos = position - lookVector * char.HumanoidRootPart.Size.Z / 2
		local properties = {Position = newPos}
		local tween = ts:Create(char.HumanoidRootPart, info, properties)
		char.HumanoidRootPart.Anchored = true

		isSliding = true
		local anim = char.Humanoid:LoadAnimation(char.Slide)
		anim.Looped = true
		if char:FindFirstChild("Humanoid") then
			for _, track in ipairs(char.Humanoid:GetPlayingAnimationTracks()) do
				track:Stop()
			end
		end
		anim:Play()
		if SlideDistance > 0 then
			tween:Play()
		end

		wait(info.Time)

		anim:Stop()
		char.HumanoidRootPart.Anchored = false
		isSliding = false
	end
end)

Can someone please help

2 Likes

is it serversided?
i need to know if it is serversided or not

It is serversided (it is activated by a remote event that fires on the control button pressed)

…​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

i cant tell whats wrong with the script

can you please try to find someone who can help?

i forgot about this
but yes i will get my friend if possible

could you send a video of what happens?

ok, thank you much for answering, I am recording them right now

here, I am going to try something, instead of using a tween, I am going to use a body velocity

didn’t work, finished the videos

robloxapp-20230328-2033487.wmv (3.3 MB)

robloxapp-20230328-2034389.wmv (98.7 KB)

robloxapp-20230328-2034492.wmv (638.3 KB)

replace char.Humanoid:LoadAnimation with char.Humanoid.Animator:LoadAnimation() and see if that fixes your issue.

I will try thisβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œβ€Œ

no, it does not work, it is still glitchedβ€Œ

Dang, this is a bad glitch and I have not found a fix yet, I think I will have to wait until someone finds a fix before I can resume making this game, thank you all for trying to help

You can use a Network Ownership approach to allow the player’s client to control their character’s movement during the slide.

Here’s a modified version of your script that uses Network Ownership:

local event = game.ReplicatedStorage.Slide
local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)

event.OnServerEvent:Connect(function(plr, camCFrame)
    local SlideDistance = plr.Character.SlideDistance.Value

    local char = plr.Character
    local isSliding = false
    local isOnSlope = false

    local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0, -1, 0) * 10)
    local hit, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, char:GetDescendants())
    if hit and normal.Y < 0.95 then
        isOnSlope = true
    end

    if char.Humanoid.FloorMaterial ~= Enum.Material.Air and not isSliding and (SlideDistance > 0 or isOnSlope) then
        -- Set network ownership to the player's client
        char.HumanoidRootPart:SetNetworkOwner(plr)

        local lookVector = Vector3.new(camCFrame.LookVector.X, 0, camCFrame.LookVector.Z).Unit

        if isOnSlope then
            local rightVector = lookVector:Cross(normal)
            if normal.Y > 0 then
                lookVector = rightVector:Cross(-normal).Unit
            else
                lookVector = rightVector:Cross(normal).Unit
            end
            SlideDistance = SlideDistance * normal.Magnitude
        end

        -- Create remote event to start slide on the player's client
        local startSlideEvent = Instance.new("RemoteEvent", plr)
        startSlideEvent.Name = "StartSlide"
        startSlideEvent.OnClientEvent:Connect(function(newPos)
            -- Slide completed, reset network ownership
            char.HumanoidRootPart:SetNetworkOwner(nil)
            startSlideEvent:Destroy()
        end)

        local myRay = Ray.new(char.HumanoidRootPart.Position, lookVector * SlideDistance)
        local hit, position = workspace:FindPartOnRayWithIgnoreList(myRay, char:GetDescendants())
        local newPos = position - lookVector * char.HumanoidRootPart.Size.Z / 2
        startSlideEvent:FireClient(plr, newPos)
    end
end)

With this change, the server will delegate control of the sliding movement to the player’s client. You’ll need to create a corresponding LocalScript to handle the sliding movement and animation on the client-side. In the LocalScript, listen for the β€œStartSlide” remote event and perform the slide:

local plr = game.Players.LocalPlayer
local char = plr.Character
local ts = game:GetService("TweenService")

local function startSlide(newPos)
    local info = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0)
    local properties = {Position = newPos}
    local tween = ts:Create(char.HumanoidRootPart, info, properties)
    char.HumanoidRootPart.Anchored = true

    local anim = char.Humanoid:LoadAnimation(char.Slide)
    anim.Looped = true
    if char:FindFirstChild("Humanoid") then
for _, track in ipairs(char.Humanoid:GetPlayingAnimationTracks()) do
            track:Stop()
        end
    end
    anim:Play()
    tween:Play()

    -- Wait for the tween to complete
    tween.Completed:Wait()

    anim:Stop()
    char.HumanoidRootPart.Anchored = false

    -- Inform the server that the slide is complete
    local startSlideEvent = plr:FindFirstChild("StartSlide")
    if startSlideEvent then
        startSlideEvent:FireServer(newPos)
    end
end

-- Listen for the StartSlide remote event from the server
plr.ChildAdded:Connect(function(child)
    if child:IsA("RemoteEvent") and child.Name == "StartSlide" then
        child.OnClientEvent:Connect(startSlide)
    end
end)

With this LocalScript, the client listens for the β€œStartSlide” remote event from the server, and when it’s fired, it performs the sliding movement and animation. Once the slide is complete, it informs the server, which then resets the network ownership of the HumanoidRootPart.

thank you, I am busy right now and I will try this later