I have a tool. Inside that tool, I have handle and a script. What I want to achieve is that when the player equips the tool, the player should slowly move upwards. The player should not be able to move right, left, back or front. Just upwards at a slow pace.
This was my attempt inside the script (normal script):
script.Parent.Equipped:Connect(function() local bodyForce = Instance.new("BodyForce", script.Parent.Handle) bodyForce.Force = Vector3.new(0, 600, 0) end)
But this does not work. I want them to float upwards continuously while equipping the tool.
How can I achieve this?
Thanks for any help
EDIT: The above script only works when I jump while my tool is equipped. I don't want that. I just want to fly upwards slowly when equipped.
Try getting the mass of the player then using the BodyForce
-- Using a part of a script I found in a ScriptingHelpers question related to yours script.Parent.Equipped:Connect(function() local character = script.Parent.Parent local hum = character:WaitForChild(“Humanoid”) groups = {["Model"] = true, ["Hat"] = true} --Dictionary; add more here. local mass = 0 function search(inst) for _,obj in pairs(inst:GetChildren()) do if groups[obj.ClassName] then search(obj) elseif obj:IsA("BasePart") then mass = mass+obj:GetMass() end end end search(character) local bf = Instance.new("BodyForce") bf.Parent = script.Parent.Handle bf.Force = Vector3.new(0,96.2,0) * mass -- adjust the pace by adjusting the 96.2 value hum.Jump = true end)
You just need to add a while loop so it does it continuously. Here's the pseudocode:
while tool equipped == true then make player fly upwards by x end