Slide System Support

I’ve been attempting to create a sliding function that ends when the key is let go, or when the speed hits 0.
I’m very new to this sorry if you see any obvious problems lol,

Issue #1: I have no idea how to tween a number, but I assume I did it correctly
Issue #2: I want to return the Slide tween so I can delete the BodyVelocity when it finishes.
Issue #3: I want to activate a “issliding” value when the slide finishes and when it starts for later usage. This is supposed to be a technical Fast-Paced movement based combat system.

SLIDE FUNCTION

local function slide(slidespeed)
	local SlideValue = Instance.new("NumberValue")
	SlideValue.Value = slidespeed
	local speed = SlideValue.Value
	Humanoid.WalkSpeed = 0
	local Slide = TweenService:Create(speed, TweenInfo.new(speed/4), {Value = 0})
	local BV = Instance.new("BodyVelocity")
	BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	Slide:Play()
	BV.Velocity = HumanoidRP.CFrame.LookVector * speed
	Slide.Completed:Connect(function()
		BV:Destroy()
		Humanoid.WalkSpeed = 16
	end)
	return BV
end

CAS FUNCTION

local function activateslide(name, state, type)
	if state == Enum.UserInputState.Begin and isrunning then
		slide(Humanoid.WalkSpeed * 1.5)
		issliding = true
	end
	if state == Enum.UserInputState.End and issliding then
		--end the tween here, which in turn destroys the bodyvelocity
	end
end

(put it in dummy terms)

tween the value object and not the value of the value object

local speed = SlideValue -- not SlideValue.Value because thats a number and cannot be tweened

edit: you also have to change the velocity of the bodyvelocity in a loop because it doesnt automatically update with the speed value

so do you suggest i use runservice for that?

create a new thread with a loop that ends when the bodyvelocity is destroyed
since youre just changing velocity, the physics engine will handle the timing so it doesnt matter what type of loop you use

task.spawn(function() -- creates new thread, code inside here doesnt interrupt the rest of the script
  while BV.Parent do -- end loop when bodyvelocity is in the game. when destroyed BV.Parent is nil
    BV.Velocity = HumanoidRP.CFrame.LookVector * speed.Value
    task.wait()
  end
end)
1 Like

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