Tool wont work when activated?

  1. I want it so that the player can drink it.

  2. The issue though is that it wont work? Script:
    aaaaww.

  3. I tried fixing it but it wont work, still no when I put Manual Activation on.

Can you help me? if its easy its fine, I don’t know how to fix it. Thank you.

1 Like

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!

1 Like

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)

Video:
robloxapp-20230505-1331280.wmv (2.3 MB)

Is the animation yours? or from someone else?

Its my animation, also it dosen’t upgrade my health. (in the game)

There are also no errors. I don’t know why?

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

Weird, I did/saved it like 2 times and its still not working, can you help?

Current Code:

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)

Proof I saved:
2

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?)

Inside the tool:
23

(the part inside the handle is the cap the brown thing, you can see it in the video i posted before this.)

what are the prints in output when you are in game and studio? use this script:

warn("tool script exist")
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()
	warn("drink activated")
	if DrinkBounce then
		warn("debounce allowed")
		DrinkBounce = false
		Char = tool.Parent
		Humroot = Char:WaitForChild("HumanoidRootPart")
		humanoid = Char.Humanoid
		warn("humanoid:", 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 printed the script, but it dosen’t still activate in the game?
robloxapp-20230505-1629341.wmv (1.3 MB)

printed the script?
I mean, I need you to take capture of all prints/warns in output and show paste it here in order to debug

here, watch the video I posted. also dont mind the other 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)


here, also don’t mind the gamepass (also it dosent upgrade my health and make me go fast?)