I have a potion system similar to realm royale. You press a key and you pull out a potion and start drinking it. I anchor the humanoid for 3.5 seconds during the animation, but for some reason he’s not un anchoring after the set time. He just stays anchored. Any idea on what I’m doing wrong?
local Player = game.Players.LocalPlayer
local Humanoid = Player.Character.Humanoid -- Humanoid
local debounce = false
local drinkSound = script:WaitForChild("drinkSound")
Player = game.Players.LocalPlayer.Character
Animation1 = Player.Humanoid:LoadAnimation(script.DrinkAnim)
CanFly = true
script.Parent.Parent.Activated:connect(function()
if debounce == false then
debounce = true
local Fly = 1
if Fly == 1 and CanFly == true then
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Animation1:Play()
wait()
drinkSound:Play()
script.Disabled = true
wait(3.5) -- Amount of time HumanoidRootPart is anchored after animation
CanFly = false
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
CanFly = true
else if Fly == 2 and CanFly == true then
end
end
task.wait(.5)
debounce = false
end
end)
On a side note, anchoring means assigning a “true” value to the “Anchored” property of the object.
Whatever you’ve done prohibits a person from moving their character, but that person can still be moved by other players should you keep player collisions enabled.
Removing that part wont change anything. It’s supposed to disable the script after the animation plays. I could be wrong on the 2nd part im still learning.
I removed the disabled part and it still stays anchored. I tried moving the .humanoid around and still no results. i feel like it’s something so simple but i cant figure it out.
I changed the code a little bit and fixed it up, you had a couple of mistakes by calling both Character and Player the same Variable. Since the character and humanoid were called too fast, they became a nil value.
Hope this works for you.
repeat wait() until game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer
local Humanoid = Player.Character:WaitForChild("Humanoid") -- Humanoid
local debounce = false
local drinkSound = script:WaitForChild("drinkSound")
Character = game.Players.LocalPlayer.Character
repeat wait() until Character:FindFirstChild("Humanoid")
Animation1 = Character:WaitForChild("Humanoid"):LoadAnimation(script.DrinkAnim)
CanFly = true
script.Parent.Parent.Activated:Connect(function()
if debounce == false then
debounce = true
local Fly = 1
if Fly == 1 and CanFly == true then
CanFly = false
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Animation1:Play()
wait()
drinkSound:Play()
wait(3.5) -- Amount of time HumanoidRootPart is anchored after animation
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
CanFly = true
else if Fly == 2 and CanFly == true then
end
end
task.wait(.5)
debounce = false
end
end)
So i think i found what’s causing the issue. This script:
local tool = script.Parent
local shield = tool:WaitForChild("Shield") --Reference the shield Value
tool.Activated:Connect(function() --On tool click do:
game:GetService("ReplicatedStorage").FillShield:FireServer(shield, tool:FindFirstAncestorOfClass("Model"):WaitForChild("Humanoid"))
-- Fire the event we created with the value and the humanoid
tool:Destroy() --Destroy (drink) the potion
end)
when i delete it from the tool everything works fine except the tool doesn’t get destroyed.
What you should be doing is adding a wait() before destroying the tool, try and match up the wait time with the other script and add a second or two to give it more time to complete the other script before destroying the tool. Here is an example:
local tool = script.Parent
local shield = tool:WaitForChild("Shield") --Reference the shield Value
tool.Activated:Connect(function() --On tool click do:
game:GetService("ReplicatedStorage").FillShield:FireServer(shield, tool:FindFirstAncestorOfClass("Model"):WaitForChild("Humanoid"))
-- Fire the event we created with the value and the humanoid
wait(4) -- Putting this .5 seconds ahead of the other script's wait time will give it time to complete the task before having it get destroyed.
tool:Destroy() --Destroy (drink) the potion
end)