Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to make the player fly upwards failed?

Asked by
Soban06 410 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
The script you put makes the player float, but they can still move? OhManXDXD 445 — 4y
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. Soban06 410 — 4y

2 answers

Log in to vote
0
Answered by
OhManXDXD 445 Moderation Voter
4 years ago
Edited 4 years ago

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)

0
Can you elaborate on the dictionary part please. I couldn't quite get it. Soban06 410 — 4y
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 OhManXDXD 445 — 4y
0
Oh ok Soban06 410 — 4y
0
This code works when I click on jump while equipping the tool. Not when I equip. But when I equip and jump. Soban06 410 — 4y
View all comments (4 more)
0
Okay let me try and edit it OhManXDXD 445 — 4y
0
Try putting the parent of the BodyForce to the character and not the handle OhManXDXD 445 — 4y
0
I did that but with no success. Soban06 410 — 4y
0
I edited the script. Try the edited version, see if it works. OhManXDXD 445 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question