Im not sure what im doing wrong, im getting no errors but the value isn’t adding up by 1, why?
if player.BulletHit.Value <= 0 then
repeat
wait(1)
player.BulletHit.Value += 1
until player.BulletHit.Value == 8
end
end
Im not sure what im doing wrong, im getting no errors but the value isn’t adding up by 1, why?
if player.BulletHit.Value <= 0 then
repeat
wait(1)
player.BulletHit.Value += 1
until player.BulletHit.Value == 8
end
end
there are 2 ends for some reason
Hey, I think you meant if player.BulletHit.Value >= 0 then
instead of if player.BulletHit.Value <= 0 then
. Also, as @elonrocket said, there are 2 ends which is why it isn’t working.
if player.Bullet.Value >= 0 wouldn’t work as it is adding values and that would continuously add more even though it is above 8.
It seems your values are all a little mixed up unless I’m misunderstanding you. Adding on to what the two above said, your code is likely meant to read like this:
if player.BulletHit.Value < 8 then --The initial check to see if the bullethit value is below 8
repeat
wait(1)
player.BulletHit.Value = player.BulletHit.Value + 1 --Add one bullethit every second
until player.BulletHit.Value >= 8 --Checks to see when bullethit is at 8 or higher which stops the code
end
it’s not working, heres the full script to get a better understanding
local shield = game.ReplicatedStorage.shield:Clone()
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
shield.Parent = character
local shieldIsOn = Instance.new("NumberValue", player)
shieldIsOn.Name = "BulletHit"
shieldIsOn.Value = 8
local weld = Instance.new("WeldConstraint")
if player.BulletHit.Value == 8 then
weld.Parent = character
weld.Part0 = shield
weld.Part1 = character.HumanoidRootPart
shield.Position = character.HumanoidRootPart.Position
shield.IsInUse.Value = true
end
if player.BulletHit.Value < 8 then
repeat
wait(1)
player.BulletHit.Value = player.BulletHit.Value + 1
until player.BulletHit.Value == 8
end
end)
I don’t see where the original code fits in this, and overall this seems all over the place… What are you trying to accomplish? That would better help me help you reach your target…
So when a player’s shield is hit , it takes damage. And when the value bullet hit goes down to 0 the player’s shield gets destroyed. But i also want the value to regenerate until it hits 8
Understood, so what you posted last is supposed to deduct a point each hit and the original post was your regeneration that is constantly running.
yeah but only when the value is getting lower it will start regenerating. Wait i think i have gave the wrong script
alright, so i gave the wrong script on accident mb
local shield = game.ReplicatedStorage.shield:Clone()
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
shield.Parent = character
local shieldIsOn = Instance.new("NumberValue", player)
shieldIsOn.Name = "BulletHit"
shieldIsOn.Value = 8
local weld = Instance.new("WeldConstraint")
if player.BulletHit.Value == 8 then
weld.Parent = character
weld.Part0 = shield
weld.Part1 = character.HumanoidRootPart
shield.Position = character.HumanoidRootPart.Position
shield.IsInUse.Value = true
end
if player.BulletHit.Value < 8 then
repeat
wait(1)
player.BulletHit.Value = player.BulletHit.Value + 1
until player.BulletHit.Value == 8
end
end)
First off, if you are wanting to check for when the BulletHit value is lowered to start regenerating, you need to run a loop to continuously check against the BulletHit value for the necessary parameter. So you would run something like this:
while wait() do
if player.BulletHit.Value < 8 then
repeat
wait(1)
player.BulletHit.Value = player.BulletHit.Value + 1
until player.BulletHit.Value >= 8
end
end
If placed correctly, this will keep making sure if the BulletHit value goes below 8 it starts recharging. Your handling of the shield removal needs reworking… Your values there seem misplaced and you are also attempting to manipulate your shield after destroying it… I’m having a hard time finding a way to resolve that bit of code as it seems too out of context.
When i get into the negatives it doesn’t work, how do i fix this? or how do i make it so the value can’t go any further below 0?
Sorry, I saw this after my last reply. You need to loop the statement like I showed you above. Otherwise it just runs once when the player is added and that’s it…
Also, I suggest waiting until greater than or equal to 8 instead of only equal to 8. This helps account for any issues that may occur that raises you above 8. As it stands now, if somehow they get 9 shield they will continue to regenerate + 1 well beyond 8, making their shield invincible…
The code I provided will work whether you went into the negatives or not.
It isn’t though, how can i prevent the value from going any more further than 0
Why just don’t use:
local myVal = player.leaderstats.Money
myVal:GetPropertyChangedSignal("Value"):Connect(function()
if myVal.Value >= 8 then
print("done")
--your code
end
end)
That didn’t work either
Can you show me your code again please?