IntValue unable to be changed

IntValue isn’t being subtracted or added in players
https://gyazo.com/4ea21abec7f67d19ee45cf1698395711

How do I fix this? code below

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
			local Life = player:WaitForChild("Life").Value
			Life = Life - 1
		end)
	end)
end)

change

local Life = player:WaitForChild("Life").Value
Life = Life - 1

to

player:WaitForChild("Life").Value = player:WaitForChild("Life").Value - 1

Properties in roblox lua are passed by value, not passed by reference.

It means, that variable Life and player:WaitForChild(“Life”).Value, will be stored in different memory addresses. Life will copy the value of player:WaitForChild(“Life”).Value, not point to it.

2 Likes

Thank you! didn’t know tat I really appreciate the help!

1 Like

I know you just helped me out but it didn’t work when I tried doing a = 0 or any other operators
https://gyazo.com/f0ed7b978e764a2471af0fa276538b8a

player.Character_Status.STAT_FOLDER:WaitForChild("Speed").Value = 0

Your intValue is named “SPEED” in the explorer, not “Speed”

I fixed it but it didn’t work !

Is there an error in the output?
What if you try player:WaitForChild(“Character_Status”):WaitForChild(“STAT_FOLDER”):WaitForChild(“SPEED”).Value
?

1 Like

it didn’t work and no theres no errors

Then, change it back and print the value before and after it is set to 0.

Also, even though there is a low possibility of that, but are you sure that the instance in the explorer is an intValue? They all look the same, so you might have confused them.

it is a IntValue but not sure why its acting like this

Ok, then print it before and after setting to 0, and send the output here.

the current value to it is 8
but once I try to print the value it said 0 (I didn’t change the value)
but when I check the actual value its 8.

I think I get it now. Are you changing that value in a local script?

no im changing it in server but I want it to change after it detected the player died

Then, I don’t know why that’s happening. If it worked for the player:WaitForChild(“Life”).Value, then it should work all the time. I will look into that tomorrow, and reply if I find the solution.

1 Like

Could you send the script? Particularly the part where you create the intValue in the player, and where you change it.