Need help with this script

local Sick = script.Parent

while true do
	task.wait(60)
	local chance = math.random(0,100)
	if chance <= 40 then Sick = true
	elseif chance >= 41 then return end
	
	end

unfortunately this doesn’t seem to work? it’s meant to randomly change a boolvalue named “Sick”, the sick value is in startergui, with the script being inside of it

image

7 Likes

In the line if chance <= 40 then Sick = true you are not specifying what property should be true so it wont do anything.

6 Likes

I made this script that should work just copy paste and tell me.

local sick = script.Parent

while task.wait(60) do
	local rng = math.random(1, 100)
	if rng <= 40 then
		sick.Value = true
		print("Success", rng)
	else
		sick.Value = false
		print("Failed", rng)
	end
end

Make this a script inside the value. (Not a local script).

9 Likes

you cant change values in local scripts. you’d have to convert this into a server script or use RemoteEvents.

8 Likes

Sick = true just makes the variable true, if sick is a boolvalue then do Sick.Value = true

6 Likes

That right

i can show example note it’s

local Sick = script.Parent

while true do
	task.wait(60)
	local chance = math.random(0,100)
	print(chance) -- you can check here where was chance was created
	if chance <= 40 then 
	Sick.Value = true -- every boolvalue always need Value=True or Value=false
	elseif chance >= 41 then
	return -- "return" it mean loop it's already stopped here similiar "break"
	end
end
5 Likes
local Sick = game.Players.LocalPlayer.PlayerGui:WaitForChild("Sick")

while true do
	task.wait(60)
	print("Does it still work here?")
	local chance = math.random(0,100)
	if chance <= 40 then Sick.Value = true
		print ("You got infected")
	elseif chance >= 41 then return end
	print("Not sick!")
	
	end

tried this as a script in serverscriptservice, but didnt work, it didnt seem to print anything either

5 Likes

I checked this one also work too

5 Likes

Try using my script inside your value just a normal script not a local.

local sick = script.Parent

while task.wait(60) do
	local rng = math.random(1, 100)
	if rng <= 40 then
		sick.Value = true
		print("Success", rng)
	else
		sick.Value = false
		print("Failed", rng)
	end
end
5 Likes

Local scripts don’t work in the ServerScriptService, Try a normal script

5 Likes

yeah that is a normal script in serverscriptservice

4 Likes

I dont think soo. i can show 1 example that script work in ServerScriptService

task.wait(1) -- just let load first
local Sick = game.Players:FindFirstChildOfClass('Player').PlayerGui:WaitForChild("Sick")

while true do
	task.wait(2) -- Previous was 60 sec
	print("Does it still work here?")
	local chance = math.random(0,100)
	print(chance)
	if chance <= 40 then Sick.Value = true
	print ("You got infected")
	return
	elseif chance >= 41 then 
	print("Not sick!")
	return 
	end
end
5 Likes

“game.Players.LocalPlayer” does not work on normal scripts

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.