So I’m making a stun system where when you get hit the IntValue named Stunned in your character goes up and when it does, a timer basically counts down until it hits 0 and then you can move again, however I came across an issue, the countdown starts everytime the value changed so if the value changes very quickly, it’s gonna keep subtracting one faster than its supposed to. (sorry if I explained wrong, heres my script)
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()
wait()
print("Fired")
local Stun = Instance.new("IntValue")
Stun.Parent = plr
Stun.Name = "Stunned"
Stun.Value = 0
Stun:GetPropertyChangedSignal("Value"):Connect(function()
if Stun.Value > 0 then
plr.Character.Humanoid.WalkSpeed = 1
plr.Character.Humanoid.UseJumpPower = true
plr.Character.Humanoid.JumpPower = 0
repeat
Stun.Value -= 1
wait(1)
until
Stun.Value <= 0
end
end)
for i = 1,20,1 do
Stun.Value = Stun.Value +1
wait(.1)
end
end)
Stun:GetPropertyChangedSignal("Value"):Connect(function()
Unrelated but you should use Changed. Stun.Changed:Connect(function(IsStun)
‘IsStun’ is a reference to the value object’s new value.
This is also unrelated, but does .Changed have a performance benefit over :GetPropertyChangedSignal? I don’t see any reason why you would change it unless it’s just easier to access the value.
.Changed does not have a performance beneift over :GetPropertyChangedSignal as .Changed fires once everytime ANY property on the instance changes
:GetPropertyChangedSignal fires once everytime the input property changes, so in certain cases, :GetPropertyChangedSignal’s performance is better than Changed.
Forummer was wrong, IsStun is not the value object’s new value, but instead the name of the property that was changed
On the other hand, Forummer would be right if he was using :GetPropertyChangedSignal, as the first parameter of that signal is the new value.
It actually is the object’s new value for things like IntValues. For any other thing though, like for example a player, it will return the name of the property that was changed. I was just wondering if it had a performance benefit when you’re using .Changed on IntValues.
.Changed does not have a performance beneift over :GetPropertyChangedSignal as .Changed fires once everytime ANY property on the instance changes
For value objects Changed only fires for changes in the ‘Value’ property.
:GetPropertyChangedSignal fires once everytime the input property changes, so in certain cases, :GetPropertyChangedSignal’s performance is better than Changed.
It’s more accurate for non-value objects but not more performant due to its use of the colon operator.
Forummer was wrong, IsStun is not the value object’s new value, but instead the name of the property that was changed
In this case ‘IsStun’ would refer to the new value of the value object’s ‘Value’ property.
On the other hand, Forummer would be right if he was using :GetPropertyChangedSignal, as the first parameter of that signal is the new value.
This isn’t the case for events/signals created via GetPropertyChangedSignal, callback functions connected to these will not receive any implicit arguments.