I am trying to make a system, where the player will constantly charge forward by holding a key bind(I already have the input part done), but gradually gets faster and faster. How would I go about doing this? This is the code I already have:
if PlayerIncoming == Player then
print("Starting Dropkick")
if UpdateConnection then
UpdateConnection:Disconnect()
end
if VelocityObject then
VelocityObject:Destroy()
end
if ForceTween and ForceTween.PlaybackState == Enum.PlaybackState.Playing then
ForceTween:Cancel()
end
VelocityObject = Instance.new("BodyPosition")
VelocityObject.Parent = Character.PrimaryPart
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = { Character }
UpdateConnection = RunService.Heartbeat:Connect(function()
print("Running")
local PositionToGo
local HumanoidRootPart = Character.PrimaryPart
local RaycastResult = Workspace:Raycast(HumanoidRootPart.Position, Vector3.new(0, 0, -20) * 5, Params)
if RaycastResult then
local FoundInstance = RaycastResult.Instance :: BasePart
if FoundInstance.CanCollide == true then
PositionToGo = RaycastResult.Position
else
PositionToGo = -(HumanoidRootPart.CFrame + (Vector3.new(0, 0, -20) * 10)).Position
end
else
PositionToGo = -(HumanoidRootPart.CFrame + (Vector3.new(0, 0, -20) * 10)).Position
end
VelocityObject.Position = PositionToGo
end)
VelocityObject.MaxForce = Vector3.new(0, 0, 0)
local PropertyTable = {
["MaxForce"] = Vector3.new(50000, 50000, 50000),
}
ForceTween = TweenService:Create(VelocityObject, TINfo, PropertyTable)
ForceTween:Play()
end
This just does not work, so could anyone help?