How can I make like the sliding speed goes down instead of goes up when players go up a slope

Hello guys! So I was trying to make realistic sliding system and… when players go up a slope, it literally speeds up
I do not know how to fix this
This sliding system uses raycast for speed

Main codes:

script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed = 25
		animation:Play()
		while true do
			
			local rayOrigin = game.Players.LocalPlayer.Character.HumanoidRootPart.Position


			local rayDestination = game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3.new(0, -10000, 0)


			local rayDirection = rayDestination - rayOrigin



			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
			raycastParams.FilterType = Enum.RaycastFilterType.Exclude
			raycastParams.IgnoreWater = true


			local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
			if raycastResult then
				
				local y = raycastResult.Normal.Y
				
				if y == 1 then
			
					script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed -= 0.10
				elseif y < 1 then
				
					script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed += 0.07
				end
				
				if script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed <= 0 or game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection.Magnitude <= 0 then
					animation:Stop()
					break
				end
		
		
			end
			
			task.wait(0)
		end

(Its poorly made lol)
Idk I’m bad at english so there could be some grammar issues

2 Likes

It speeds up becase you are increasing the speed?

script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed += 0.07

What’s the problem exactly?

I mean the walkspeed increases when players goes up a slope that it isn’t supposed to be

So you want it to slow down instead of speed up?

2 Likes

Yep, thats what I wanted. I have no idea how to make it like that

Then subtract instead of add to walkspeed?

Yeah, I wanna make it slow down

Use minus instead of plus? What’s the problem?

-_- he said substract instead of adding but i don’t understand how this script is supposed to detect if a player is going up or down a slope

1 Like

Ill show you entire script

uis = game:GetService("UserInputService")
animation = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(script:WaitForChild("sliding"))
animation.Priority = Enum.AnimationPriority.Action4
uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.C and script.Parent.running.Value == true then
		
		script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed = 25
		animation:Play()
		while true do
			
			local rayOrigin = game.Players.LocalPlayer.Character.HumanoidRootPart.Position


			local rayDestination = game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3.new(0, -10000, 0)


			local rayDirection = rayDestination - rayOrigin



			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
			raycastParams.FilterType = Enum.RaycastFilterType.Exclude
			raycastParams.IgnoreWater = true


			local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
			if raycastResult then
				
				local y = raycastResult.Normal.Y
				
				if y == 1 then
					
					script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed -= 0.10
				elseif y < 1 then
				
					script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed += 0.07
				end
				
				if script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed <= 0 or game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection.Magnitude <= 0 then
					animation:Stop()
					break
				end
			print(y)
				
				
			end
			
			task.wait(0)
		end
	end
end)


The codes are from local script Btw (I cant make anything else except raycast cause I’m bad at scripting)

1 Like

i may just be dumb and what you’re doing works but i feel like you have to use angles to detect if a player is actually going up or down not just the vector

Well, thanks. I should try this

I might be dumb cause I didnt really speific it and I made it very poorly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.