Repeat wait not working

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")
	while wait() do
	if player.BulletHit.Value == 8 then
	weld.Parent = character
	weld.Part0 = shield
	weld.Part1 = character.HumanoidRootPart
	shield.Position = character.HumanoidRootPart.Position
	shield:WaitForChild("IsInUse").Value = true
	end
end
	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
end)

I changed it back because it wasn’t working

So it didn’t print done if you had more than 8 bullets?

more than 8 bullets?

why did you remove your post?

Well I don’t fully understand what do you want to achieve.

whenever the player has his shield it protects the player but when the value goes down i want the value to increase by 1 but it isn’t increasing

while wait() do
wait(1) 
		if player.BulletHit.Value <= 8 then
	     player.BulletHit.Value = player.BulletHit.Value + 1
		end
	end

Try this.

like this?

while wait() do
		if player.BulletHit.Value < 8 then
			repeat
			player.BulletHit.Value = player.BulletHit.Value + 1
			wait(1) 
			until player.BulletHit.Value == 8
		end
	end

Because i want it to stop at 8

Try my edited version of the code now.

the value is not adding by 1

Oh I should make the wait on the top of the loop try it now.

it still doesn’t add the value

Can you try to print (“hello there”) after the if statement in the loop?

Oh I know what’s your problem, you have two loops that means the second one won’t work.

Oh, what do i do instead? because it also didn’t print

Put everything inside one loop.

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")
	while wait() do
wait(1) 
		if player.BulletHit.Value < 8 then
	     player.BulletHit.Value = player.BulletHit.Value + 1
		end
	if player.BulletHit.Value == 8 then
	weld.Parent = character
	weld.Part0 = shield
	weld.Part1 = character.HumanoidRootPart
	shield.Position = character.HumanoidRootPart.Position
	shield:WaitForChild("IsInUse").Value = true
	end
end
end)
1 Like

what do you mean, isn’t it in already in one? Im prob wrong

Alright try this version of your code ^.

It worked! :smiley: thank you for the help

No problem the problem was anything below the while wait() loop won’t run because the loop is infinite :smiley:.

1 Like