I seem to have spaghettied something up here. This function is supposed to check for an IntValue, who's value is incremented by picking up an item in the world. However, even if you pick up said item, the animation and the healing won't work, They only work when I add a script under the IntValue setting it to any positive number. I can see in the explorer that the Value increments correctly when I pick the item up. But it seems to ignore that and rely entirely on the Script that sets the value manually. Why is this happening?
local humanoid = script.Parent:FindFirstChild("Humanoid")
local stims = humanoid.Stims.Value
local casing = humanoid.Parent.animSyringe.Casing
local plunger = humanoid.Parent.animSyringe.Plunger
local needle = humanoid.Parent.animSyringe.Needle
local serum = humanoid.Parent.animSyringe.Serum
local player = game.Players.LocalPlayer
local healing = 30
local canHeal = false
local coolDown = true
local keyBind = "f"
local mouse = player:GetMouse()
mouse.KeyDown:Connect(function(key)
if key == keyBind then
if stims > 0 and humanoid.Health + healing <= 100 and humanoid.Health < 100 and coolDown == true then
canHeal = true
end
if canHeal == true then
casing.Transparency = 0
plunger.Transparency = 0
needle.Transparency = 0
serum.Transparency = 0
local animation = humanoid:LoadAnimation(script.Animation)
animation:Play()
wait(animation.Length)
casing.Transparency = 1
plunger.Transparency = 1
needle.Transparency = 1
serum.Transparency = 1
if humanoid.Health + healing > 100 then
humanoid.Health = 100
else
humanoid.Health += healing
end
stims = stims - 1
canHeal = false
coolDown = false
wait(10)
coolDown = true
end
end
end)

1 comment
Your [[stims]] variable isn't correctly written. If we pretend humanoid.Stims.Value is 5 when you make your [[stims]] variable. Then the value of [[stims]] won't change from 5 if humanoid.Stims.Value changes because you've only saved the current value of it. Remove .Value on line 2 and add .Value whenever you use your [[stims]] variable