Hi everyone, I wanna know how to make a script where when you hold a gear and click, it charges infront of you at a rapid speed without letting the player control during the charge. How would I be able to do that?
Here a gif of what I want underneath:
(I used walkspeed to demonstrate what I want using velocity instead of walkspeed.)
I was thinking of using velocity but it felt complicated to script it with where the angle of the user is at, etc…
local PS = game:GetService("Players")
local player = PS.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local HRP: BasePart = char:FindFirstChild("HumanoidRootPart")
HRP.AssemblyLinearVelocity *= (HRP.CFrame.LookVector * 10)
You can use the humanoid’s lookvector to get the correct velocity like downrest posted, also the reason why your script is erroring at line 5 is because
local HRP: BasePart = character:FindFirstChild("HumanoidRootPart")
should be
local HRP = character:FindFirstChild("HumanoidRootPart")
Try this for your charge
local debounce = false
local velocity = 100
local chargetime = 1
local plyr = game.Players.LocalPlayer
script.Parent.Activated:Connect(function()
if not debounce and plyr.Character then
debounce = true
local character = plyr.Character
local oldws = character.Humanoid.WalkSpeed
character.Humanoid.WalkSpeed = 0
local timer = tick()
repeat
character.HumanoidRootPart.AssemblyLinearVelocity = character.HumanoidRootPart.CFrame.LookVector*velocity
task.wait()
until tick() - chargetime >= timer or not plyr.Character
character.Humanoid.WalkSpeed = oldws
debounce = false
end
end)
The only issue is that shiftlock or going first person will allow you to change the trajectory of the charge, so you would either have to disable shiftlock or save the initial direction of the charge as a variable before the repeat loop starts.