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

why don't I stop floating?

Asked by 8 years ago
Char = script.Parent.Parent

b = Instance.new("BodyPosition")
b.Parent = Char.Character.Torso
b.Position = Vector3.new(0,11.36,0)
b.MaxForce = Vector3.new(0,2300,0)
--this script works but the problem is I need it to only work when  I touch a part In workspace What am i doing wrong?

1 answer

Log in to vote
0
Answered by
rexbit 707 Moderation Voter
8 years ago

The Touched event will help you in your current condition. It loads the code that is found within the event once the specific Object is touched.

local BP = Instance.new("BodyPosition")

function FloatEnable(obj)
    BP.Parent = obj:WaitForChild("Torso")
    BP.Position = Vector3.new(0,11.36,0)
    BP.MaxForce = Vector3.new(0,2300,0)
end

workspace.PART.Touched:connect(function(obj_hit)
    if obj_hit.Parent:WaitForChild("Humanoid") then
        FloatEnable(obj_hit.Parent)
    else
        print("Not Humanoid")
    end
end)

workspace.PART.TouchEnded:connect(function()
    BP:remove()
end)
Ad

Answer this question