Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Attempt to make the player fly upwards failed?

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.

2 comments

0

The script you put makes the player float, but they can still move?

0

Actually, what this script does right now is that when I equip the tool, the player's jump increases slightly. Like you know when you equip the gravity coil, your gravity decreases. Just like this (I am not making a gravity coil). But I want the player to keep going upwards.

2 answers

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)

8 comments

0

Can you elaborate on the dictionary part please. I couldn't quite get it.

0

It’s supposed to check the type of item in the Dictionary, for example, the [“Hat”] = True will look for hats and find the mass of them, and add it to the total mass

0

Oh ok

0

This code works when I click on jump while equipping the tool. Not when I equip. But when I equip and jump.

0

Okay let me try and edit it

0

Try putting the parent of the BodyForce to the character and not the handle

0

I did that but with no success.

0

I edited the script. Try the edited version, see if it works.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.