Number value isn't updating after subtracting in module script

local function SHC(Hum,Result,Shield)
	Shield -= Result

	if Shield > 0 then
		print("SHIELD =",Shield)
	elseif Shield < 0 then
		Hum.Health += Shield
		print("SHIELD =",Shield)
		print("HEALTH =",Hum.Health)
	end
end

--Stats--

--Health Calcuations

module.DAC = function(Hum,Damage,Values) 
	local Shield = Values.Shield.Value
	local Defense = Values.Defense.Value
	local Modifier = Values.DMGModifier.Value
	local Result = Round((Damage - Damage / 100 * Defense) * Modifier)

	if Shield == 0 then
		Hum.Health -= Result
		print("HP DIFF =",Result)
	else
		SHC(Hum,Result,Shield)
	end
end

Module script ^

Negative.Touched:Connect(function(hit)
	if CD == false then
		local Values = hit.Parent:WaitForChild("Handler").Values
		local Char = hit.Parent
		
		module.DAC(Char.Humanoid,25,Values)
		Cooldown()
	end
end)

Script ^

1 Like

Because you’re updating them as a local variable to update then you need to do BlaBlaBla.Value = Shield or nah…

2 Likes

I’ve already tried Shield.Value = Shield - Result. It prints out 25, but it never saves the changes to the server and remains as 50

1 Like

Also, use TakeDamage on a humanoid, not Humanoid.Health =- Result. And about your problem… idk bro, i can’t figure it out!

2 Likes

Yeah, I’ve been at it for an hour or two. BTW, why would I use Humanoid:TakeDamage() ?

Basically, Humanoid.Health -= blabla is the same as TakeDamage(), sooo idk… I’m just more used to TakeDamage().

Probably not worth updating all of my code to use :TakeDamage() instead then

there’s no reason to use it, infact health -= executes faster, but at this little difference, it doesn’t matter at all, use whichever you’d like.
image

2 Likes

Thank you, would you know anything about my problem ?

image
Forgot to post this. Shield is a number value.

You might want to try Shield.Value :slight_smile:

Already have, plus I’ve already got it in the variable
image

Would you be comfortable with sharing a copy of your game? Would make it easier for me to debug

Nope. This is all of the relevant code

1 Like

yeah so when doing

SHC(Hum,Result,Shield)

you are only passing in the shield’s value, not a reference to it, you’d have to pass Values.Shield, and subtract Result from Shield.Value inside ur SHC function

1 Like

that sounds quite plausible… give me a moment

I have already tried this, but for some reason when you mention it, it works lol…
thank you

Bro… Didn’t i answered something similar like that before? :neutral_face::neutral_face::neutral_face:

BlaBlaBla.Value = Shield or nah…

i don’t believe thats a properly reply, also he had to pass in the instance which you didn’t tell him, he would have kept passing in the number and trying to access its Value property

Edit: stop replying to the post, its solved

1 Like

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