I want my text label to increase the kill value text by one every time a kill is gained in the leaderstats
The issue is my script only increases the kill value once and doesn’t seem to work after that (it works if the script resets to 1 kill, then after reaching 2 kills is the part where the script breaks)
I have looked in the devforum but it seems like once again, i’m the only one with this problem
The code i made:
Kills.Changed:Connect(function(newKill)
killGui.KillText.Visible = true
if newKill > oldKill and newKill - oldKill == 1 and not Running then
killGui.KillText.Text = "+"..newKill - oldKill.." kill!"
end
if newKill > oldKill and newKill - oldKill == 1 and Running then
newKill += 1
killGui.KillText.Text = "+"..newKill - oldKill.." kills!"
newKill -= 1
end
end)
(this is a shortened version of my script, the “Running” variable just acts as a breaker so the if statements work as they should, i will post the extra code if needed)
Kills.Changed:Connect(function(newKill)
killGui.KillText.Visible = true
if newKill > oldKill and newKill - oldKill == 1 and not Running then
killGui.KillText.Text = "+"..newKill - oldKill.." kill!"
end
if newKill > oldKill and newKill - oldKill == 1 and Running then
newKill += 1
killGui.KillText.Text = "+"..newKill - oldKill.." kills!"
newKill -= 1
end
oldKill = newKill
end)
New reply because your reply was edited, the second if statement does not run unless the first if statement runs first, there is a tick() underneath the if statements and while it is active it makes the running variable true, therefore the second if statement cannot be ran at the first kill update
Please correct me if I’m wrong, but I’m pretty sure the argument for new value for Changed and :GetPropertyChangedSignal() are broken and don’t seem to work. So, you have to define the new value yourself in the function.
By broken, I mean the event works good. But, the issue is that the argument sometimes work and sometimes doesn’t. That’s why, you have to use:
Instance.Changed:Connect(function(newValue --[[Doesn't always provide the new value and sometimes return nil]])
local newVal = Instance.Value -- This returns the new value always.
end)
no because for example if the player got 8 kills and the old kill value was 7 it would remain with 1 because we are subtracting the newKill with the oldKill, i would have to use > if there was explosives or aoe in my game