Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

win script not doing anything when value is reached?

my value script is not working it does not do anything when it gets to the value help

there was no error in the output

script :

Health2 = game.ReplicatedStorage.SafeHealth2

Health1 = game.ReplicatedStorage.SafeHealth1

Healthtoloser = 2

Win = script.Parent.Parent.Win

Text = script.Parent.winner

while true do
	wait(0.5)
	if Health2.Value < Healthtoloser then
		Win.Visible = true
		Text.Text = "Great Britain Wins!"
		print("BritWins")
		wait(5)
		Health2.Value = 4000
		Health1.Value = 4000
		Win.Visible = false
	end
end
while true do
	wait(0.5)
	if Health1.Value < Healthtoloser then
		Win.Visible = true
		Text.Text = "Great Britain Wins!"
		print("BritWins")
		wait(5)
		Health2.Value = 4000
		Health1.Value = 4000
		Win.Visible = false
	end
end

2 comments

0

The 2nd while true do loop does not play since there is already one above it, you should combine both of those if statements into one loop.

0

building on what will said, lua will run code from left to right, top to bottom, when it hits a while loop it'll jump back to the top of the loop before continuing on, and since the top loop never breaks, the bottom loop never gets ran.

1 answer

So, First at the top of your script:

Health2 = game.ReplicatedStorage.SafeHealth2
Health1 =  game.ReplicatedStorage.SafeHealth1

You are calling the child of replicated storage before you use game:GetService("ReplicatedStorage")

and After you get the service "Replicated Service" you need to use

:WaitForChild 
--For this example rp = replicated service variable

local Health1 = rp:WaitForChild("SafeHealth1")
local Health2 = rp:WaitForChild("SafeHealth2")

Now all the way at the bottom of your script where you have:

Win.Visible = false

Instead of putting it in both loops you can do:

while true do
	if x < 4 then
		print(x)
	else 
		print("You Lose")
	Win.Visible = false
	end
end

This way the Win.Visible activates on both sides but only needing to write it once.

My Solution:

local rp = game:GetService("ReplicatedStorage")
local Health1 = rp:WaitForChild("SafeHealth1")
local Health2 = rp:WaitForChild("SafeHealth2")

local win = game.Workspace.Part

while true do
	wait (0.5)
		if Health2.Value > Health1.Value then
			win.Transparency = 0
			print("Health 2 wins")
		wait(2)
		Health2.Value = 1
		Health1.Value = 3
		
	else 
		win.Transparency = 0
		print("Health 1 wins")
		wait(2)
		Health1.Value = 1
		Health2.Value = 3
	end
	win.Transparency = 1
	
end

This discussion is preserved as it was. New answers, comments, and votes are closed.