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

How can I make a humanoid bob in the water?

Asked by 8 years ago

I tried to make a bobbing effect when someone walks into a water block. Put this into a a part and you will end up flying. To people who don't want to see the full script, it basically adds a bodyforce and removes it after a second, to make it go up a little, and then go back down so another bodyforce gets added. For some reason, it just makes the player fly to heaven :/

touching = false
chr = nil
debounce = false

script.Parent.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
chr = hit.Parent
touching = true
if not debounce then
debounce = true
end
while touching do
wait()
if chr and chr:FindFirstChild("Humanoid").Health > 0 and hit.Name == "Torso" then
local upforce = Instance.new("BodyForce")
upforce.force = Vector3.new(0,5000,0)
upforce.Parent = hit
game.Debris:AddItem(upforce,2)
debounce = false
wait(3)
end
end
end
end)

script.Parent.TouchEnded:connect(function(hit)
if chr then
if hit.Parent == chr then
chr = nil
touching = false
end
end
end)

Answer this question