Ok, so the drink will only work if DrinkBounce is true, but the script starts off with having DrinkBounce off, so it will never run. One way to fix this is to have DrinkBounce enabled from the beginning, disabling it when the function is ran, and making it true again after some seconds.
Here’s a simple code for this:
local DrinkBounce = true
tool.Activated:Connect(function()
if DrinkBounce == true then
DrinkBounce = false
-- Code here
task.wait(1)
DrinkBounce = true
-- At this point, the tool can be activated again, feel free to put more code here if you need to.
end
end)
This should work (Probably, I haven’t tested). Feel free to tell me if it doesn’t work or if you have any other issues!
Thank you, it works now I was stuck on this error yesterday. But there’s another problem. When I play the game in Roblox (not studio), it dosen’t work. Can you help me? thanks. (also I saved/published it)
Paste here your current code.
If its working in Studio and its not working in game, the animation is yours, then maybe you forgot to Publish/Update your place, Alt + P
local tool = script.Parent
local Handle = tool:FindFirstChild("Handle")
local Anim = tool.Animation
local humanoid = {}
local Humroot = {}
local Char = {}
local DrinkBounce = true
tool.Activated:Connect(function()
if DrinkBounce == true then
DrinkBounce = false
Char = tool.Parent
Humroot = Char:WaitForChild("HumanoidRootPart")
humanoid = Char.Humanoid
local Animation = humanoid:LoadAnimation(Anim)
Animation:Play()
Animation.Stopped:Wait()
humanoid.WalkSpeed = 30
humanoid.MaxHealth = humanoid.MaxHealth +100
humanoid.Health = humanoid.MaxHealth
tool:Destroy()
humanoid.WalkSpeed = 16
task.wait(1)
DrinkBounce = true
-- At this point, the tool can be activated again, feel free to put more code here if you need to.
end
end)
I dont see a specific issue in your code that could cause it to not work. I moved some lines, changed others, and added prints in output so you can check the behaviour in game and studio
local tool = script.Parent
local Handle = tool:FindFirstChild("Handle")
local Anim = tool.Animation
local humanoid
local Humroot
local Char
local DrinkBounce = true
tool.Activated:Connect(function()
if DrinkBounce then
DrinkBounce = false
Char = tool.Parent
Humroot = Char:WaitForChild("HumanoidRootPart")
humanoid = Char.Humanoid
local Animation = humanoid.Animator:LoadAnimation(Anim)
Animation:Play()
Animation.Ended:Wait()
--Animation.Stopped:Wait()
warn("Drinking done")
humanoid.WalkSpeed = 100
humanoid.MaxHealth = humanoid.MaxHealth + 100
humanoid.Health = humanoid.MaxHealth
tool:Destroy()
task.wait(5)
warn("effect ended")
humanoid.WalkSpeed = 16
DrinkBounce = true
end
end)
It works in studio but not the game, again. It must be a bug/glitch? also the game makes the player automatically go first person. (the other tools work except this one?)
When I did read your script, my first thought was, that you are Destroying() the tool, and the tool has the script, meaning you are deleting the script. When the script is Destroyed() the script still task.wait(3) seconds, to perform warn("effect ended") and reduce back WalkSpeed to 16.
But that effect ended is not printing, and I tested it in Studio, and it prints, which is kinda weird cause the script is supposedly destroyed(), so it should not print, but in fact the function thread still allocated in memory and the script parented to nil and still runs in Studio.
So my first idea is that in real game, it becomes garbageCollected before running the effect ended line… Im not sure.
For debugging, remove the tool:Destroy() line, so the script never gets destroyed, do the test in real game and take a screen capture of the console, not needing a video (which is extremely pixelated because you are recording with the roblox inbuilt recorder, its hard to read and watch)