I’m using a script that makes it so when the player enters water holding out the floaty tool it makes them glide on the water in the floaty. My main issue though is having an animation of the player sitting in the floaty be used instead of them in a state of falling. I’ve tried running an animation during the Equipped function, but none of the tries have worked. Here’s the code.
local tool = script.Parent
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local function printHumanoidState()
local character = player.Character
local humanoid = character and character:FindFirstChild("Humanoid")
if not humanoid or not character then return end
print("Current humanoid state: ", humanoid:GetState())
end
local function onEquipped()
print("Tool has been equipped.")
local character = player.Character
local humanoid = character and character:FindFirstChild("Humanoid")
if not humanoid or not character then return end
if humanoid:GetState() == Enum.HumanoidStateType.Swimming then
print("Player is swimming.")
local bodyPosition = Instance.new("BodyPosition")
bodyPosition.Position = character.HumanoidRootPart.Position + Vector3.new(0, 5, 0)
bodyPosition.Parent = character.HumanoidRootPart
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
bodyVelocity.Parent = character.HumanoidRootPart
end
local function isTouchingWater()
local character = player.Character
local humanoid = character and character:FindFirstChild("Humanoid")
if not humanoid or not character then return false end
if humanoid.FloorMaterial == Enum.Material.Water then
return true
else
return false
end
end
if isTouchingWater() then
humanoid:SetStateEnabled("Swimming", true)
end
end
local function onUnequipped()
print("Tool has been unequipped.")
local character = player.Character
if character then
if character.HumanoidRootPart:FindFirstChild("BodyPosition") then
character.HumanoidRootPart.BodyPosition:Destroy()
end
if character.HumanoidRootPart:FindFirstChild("BodyVelocity") then
character.HumanoidRootPart.BodyVelocity:Destroy()
end
end
end
local function swimno()
script.Parent.Parent:WaitForChild("Humanoid"):SetStateEnabled("Swimming", false)
end
local function swimyes()
script.Parent.Parent.Parent.Character:WaitForChild("Humanoid"):SetStateEnabled("Swimming", true)
end
tool.Equipped:Connect(onEquipped)
tool.Equipped:Connect(swimno)
tool.Unequipped:Connect(onUnequipped)
tool.Unequipped:Connect(swimyes)
while wait(1) do
printHumanoidState()
end
Also, I’ve set the priority of the sit animation as idle.