Damage script not cancelling

I am making two objects - a bloxy cola that increases your speed at the cost of damaging you, and medicine that basically cancels out all negative effects and heals you.

Problem: I made it so the medicine turns a function in the character to “False”, which the damage script should detect and then STOP damaging the player. (It didn’t work, shocker)

image
This is the script location, effects has the value.
image

– Scripts below –
Medicine Script:

local debounce = false
local tool = script.Parent
local handle = script.Parent.Handle
local UseCount = script.Parent.TimesUsed.Value
local UseEvent = tool.UseEvent

local plr = game.Players:GetPlayerFromCharacter(tool.Parent) or tool.Parent.Parent
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local AnomalyValue = char:GetDescendants()

local Empty = handle.EmptyAnim
local Equip = handle.EquipAnim
local Use = handle.UseAnim

local EmptyAnimation = humanoid.Animator:LoadAnimation(Empty)
local EquipAnimation = humanoid.Animator:LoadAnimation(Equip)
local UseAnimation = humanoid.Animator:LoadAnimation(Use)

-- Config --
local HPHeal = 9999999

tool.Equipped:Connect(function()
	local CurrentWS = humanoid.WalkSpeed
	if debounce == true then return end -- If equipped
	debounce = true
	EquipAnimation:Play()
	EquipAnimation.Ended:Wait()
	debounce = false
end)

tool.Activated:Connect(function()
	if debounce == true then return end -- If in use
	debounce = true
	if UseCount >= 3 then -- If used more than once
		EmptyAnimation:Play()
		tool.ToolTip = "Looks like a casual bottle of medicine. [EMPTY]"
		EmptyAnimation.Ended:Wait()
		print("Instance of CA-500 is now empty.")
	else -- If not, proceed
		UseCount += 1
		UseAnimation:Play()
		UseAnimation.Ended:Wait()
		UseEvent:FireClient(plr)
		for i,v in pairs(AnomalyValue) do -- Find CA-207 effects
			if v:IsA("BoolValue") and v.Name == "SodaUsed" then
				v.Value = false
			end
		end
		humanoid.Health += HPHeal
		debounce = false
	end
end)

Bloxy Cola script:

local debounce = false
local tool = script.Parent
local handle = script.Parent.Handle
local UseCount = script.Parent.TimesUsed.Value
local DrinkEvent = tool.DrinkEvent

local plr = game.Players:GetPlayerFromCharacter(tool.Parent) or tool.Parent.Parent
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local DrinkValue = char:GetDescendants()

local Empty = handle.Empty
local Equip = handle.Equip
local Drink = handle.Drink

local AnimEquip = humanoid.Animator:LoadAnimation(Equip)
local AnimDrink = humanoid.Animator:LoadAnimation(Drink)
local AnimEmpty = humanoid.Animator:LoadAnimation(Empty)

-- Config --
local SpeedtoChange = 32

tool.Equipped:Connect(function()
	local CurrentWS = humanoid.WalkSpeed
	if debounce == true then return end -- If in use
	debounce = true
	humanoid.WalkSpeed = 0
	AnimEquip:Play()
	AnimEquip.Ended:Wait()
	humanoid.WalkSpeed = CurrentWS
	debounce = false
	end)

tool.Activated:Connect(function()
	if debounce == true then return end
	debounce = true
	if UseCount >= 1 then -- If used more than once
		AnimEmpty:Play()
		AnimEmpty.Ended:Wait()
	else -- If not, proceed
		UseCount += 1
		AnimDrink:Play()
		AnimDrink.Ended:Wait()
		DrinkEvent:FireClient(plr)
		for i,v in pairs(DrinkValue) do
			if v:IsA("BoolValue") and v.Name == "SodaUsed" then
				v.Value = true
			end
		end
		humanoid.WalkSpeed = SpeedtoChange
		tool.ToolTip = "Seems like a normal cola.. [EMPTY]"
		debounce = false
		end
end)

Damage over time script:

local Humanoid = script.Parent:WaitForChild("Humanoid")
local Char = script.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(Char)
local Effects = Char.Effects
local DrinkUsed = Effects.SodaUsed

DrinkUsed.Changed:Connect(function()
	if DrinkUsed == true then
while wait(2) do
		print("Damage dealt.")
		Humanoid:TakeDamage(5)
		end
	else
		print("nothing.")
	end
end)

Before you ask, yes, the medicine does set the value to false, but the script doesn’t seem to detect it somehow… (Or I’m very stupid). The scripts return no errors, but for some reason, the damage script skips the damage part when used and goes to print("Nothing.")

All in all, I’d love if someone helped me, thank you! (I am going mentally insane)

1 Like

DrinkUsed looks like to be only the object. To get the value, you need to do DrinkUsed.Value.

For your cancelling problem, simply break the while loop if DrinkUsed.Value == false

local Humanoid = script.Parent:WaitForChild("Humanoid")
local Char = script.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(Char)
local Effects = Char.Effects
local DrinkUsed = Effects.SodaUsed

DrinkUsed.Changed:Connect(function()
	if DrinkUsed.Value == true then
        while wait(2) do
        if (DrinkUsed.Value == false) then break; end;
		print("Damage dealt.")
		Humanoid:TakeDamage(5)
		end
	else
		print("nothing.")
	end
end)
1 Like

May I ask why the if (DrinkUsed.Value) is in parentheses?

1 Like

Oh, its just my style of scripting. I apologize.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.