i have a body velocity area which when touch you get bodyvelocity and when touch ended it gets destroyed
You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
i want to stop the bodyvelocity being destroyed when i equip tools
- What is the issue? Include screenshots / videos if possible!
when i equip tool the touch ended event fires and then the bodyvelocity will be destroyed
- What solutions have you tried so far? Did you look for solutions on the Creator Hub?
i tried attributes that tracks if you get boosted but if you boost and get out of the body velocity area with the attribute on you will still have body velocity.
and also i tried to do something when player equip tool but if you spam equip tool and get out of the body velocity area
here is the body velocity area script that makes the player have body velocity on touch but when touch ended then it will be destroyed
local Elevator = {}
function Elevator.Elevate(Part: BasePart)
local elevator = Part
local debounce = false
elevator.Touched:Connect(function(hit)
if debounce == false then
local humanoidrootpart = hit.Parent:FindFirstChild("HumanoidRootPart")
if humanoidrootpart and humanoidrootpart:FindFirstChildOfClass("BodyVelocity") then return end
local bodyvelocity = Instance.new("BodyVelocity")
bodyvelocity.Name = "bodyvelocity"
local upvector = elevator.CFrame.UpVector
local maxforce=Vector3.new(0,Part:GetAttribute("MaxForce"),0)
if upvector.X ~= 0 then maxforce = Vector3.new(Part:GetAttribute("MaxForce"), Part:GetAttribute("MaxForce").Y, Part:GetAttribute("MaxForce").Z) end
if upvector.Z ~= 0 then maxforce = Vector3.new(Part:GetAttribute("MaxForce").X, Part:GetAttribute("MaxForce").Y, Part:GetAttribute("MaxForce")) end
bodyvelocity.Parent = humanoidrootpart
bodyvelocity.MaxForce = maxforce
bodyvelocity.Velocity = elevator.CFrame.UpVector * Part:GetAttribute("Speed")
end
end)
local ignoreTouchEndCounter = 0
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
-- Track Tools being added
char.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
ignoreTouchEndCounter += 1
task.spawn(function()
task.wait(0.1) -- short delay to ignore TouchEnded
ignoreTouchEndCounter -= 1
end)
end
end)
-- Track Tools being removed
char.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
ignoreTouchEndCounter += 1
task.spawn(function()
task.wait(0.1) -- short delay to ignore TouchEnded
ignoreTouchEndCounter -= 1
end)
end
end)
end)
end)
elevator.TouchEnded:Connect(function(hit)
if ignoreTouchEndCounter > 0 then return end
if hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
local humanoidrootpart = hit.Parent.HumanoidRootPart or hit
print(hit)
if humanoidrootpart:FindFirstChild("bodyvelocity") and (hit.Parent:FindFirstChild("Humanoid")) then humanoidrootpart.bodyvelocity:destroy() print("BOdy velocity destryed") end
end
end)
end
return Elevator
body velocity area boost script if you have body velocity on then this thing make you have a higher or lower velocity for a certain time
local elevatorBoost = {}
local CS = game:GetService("CollectionService")
local TS = game:GetService("TweenService")
local debounce = {}
function elevatorBoost.Boost()
local Boosters = CS:GetTagged("elevatorBoost")
for i, Booster: BasePart in Boosters do
Booster.Touched:Connect(function(hit)
local char = hit.Parent
if debounce[char] then return end
debounce[char] = true
local Humanoid: Humanoid = char:FindFirstChild("Humanoid")
if Humanoid then
local bodyVelocity: BodyVelocity = Humanoid.RootPart:FindFirstChildOfClass("BodyVelocity")
if bodyVelocity then
-- Store the original velocity BEFORE any modifications
local originalVelocity = bodyVelocity.Velocity
-- Calculate the boost vector using the part's UpVector
local boostVector = Booster:GetAttribute("Boost") or Vector3.zero
-- Apply the boost
bodyVelocity.Velocity = originalVelocity + boostVector
-- Get duration from the booster
local Duration = Booster:GetAttribute("Duration") or 2
-- One-time connection for when a Tool is equipped
-- Use spawn or coroutine instead of task.wait to avoid blocking
task.spawn(function()
task.wait(Duration/2)
--Tween back to original velocity
local Tween: Tween = TS:Create(bodyVelocity, TweenInfo.new(Duration), {Velocity = originalVelocity})
Tween:Play()
Tween.Completed:Wait()
print("Can touch again (tween end)")
debounce[char] = false
end)
else
debounce[char] = false
end
else
debounce[char] = false
end
end)
end
end
return elevatorBoost