Hey, i have a script for the round system, and the main game, (my script is a russian roulette-styled game), there is no errors in the output, but it dosent work.
The script is located inside a textlabel (is a localscript).
The complete code:
local bullets = {"blank", "blank", "blank", "blank", "blank", "live"}
local blanks = 0
local m = game.Players.LocalPlayer:GetMouse()
local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local livel = 1
local canRoll = true
local canclick = false
local p = game.Players.LocalPlayer
local db = true
local yturn = false
local int = true
local plrs = game.Players:GetChildren()
local selectedp = plrs[math.random(1, #plrs)]
local gui = script.Parent
local intVal = 10
local tool = game.StarterPack.Revolver
local ch = p.CharacterAdded:Wait()
local idle = Instance.new("Animation")
local shoot = Instance.new("Animation")
local roll = Instance.new("Animation")
roll.AnimationId = script.Roll.AnimationId
shoot.AnimationId = script.Shoot.AnimationId
idle.AnimationId = script.Shoot.AnimationId
local trackidle = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Animator:LoadAnimation(idle)
local trackroll = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Animator:LoadAnimation(roll)
local trackshoot = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Animator:LoadAnimation(shoot)
tool.Parent = game.StarterPack
trackroll.Priority= Enum.AnimationPriority.Action4
local function round()
gui.Text = selectedp.Name.." Gets the gun..."
if selectedp.Name == game.Players.LocalPlayer.Name then
yturn = true
else
yturn = false
end
end
if int then
gui.Text = "Intermission..."
wait(10)
gui.Text = "Game starting..."
wait(5)
gui.Text = "Game started, good luck..."
wait(3)
round()
wait(2)
db = false
end
local function shoot()
wait(3)
local sb = math.random(1, #bullets)
print(sb)
if sb == 6 then
print("Live")
livel -= 1
script.Parent.Text = "There was a bullet, bad luck... There is "..livel.." Bullets left."
hum.Health = 0
else
blanks += 1
print("Blank")
script.Parent.Text = p.Name.." are lucky... There is "..livel.." Bullets left."
end
if blanks == 5 then
sb = 6
end
end
local function click()
local shootval = 0
shoot()
shootval = shootval + 1
print("Shooted "..shootval.." Times.")
end
m.Button1Up:Connect(function()
if canclick and yturn == true and db == false then
db = true
trackshoot:Play()
trackshoot.Looped = false
script.Parent.Text = selectedp.Name.." Shoot the gun..."
print("Shooted")
click()
yturn = false
wait(5)
local selectedp = plrs[math.random(1, #plrs)]
round()
tool.Parent = game.StarterPack
db = false
else
canclick = true
end
end)
if yturn == true then
tool.Parent = ch
end
local alive = workspace.Players:GetChildren()
if #alive <= 1 then
gui.Text = "You are lucky, "..alive[1].Name.."..."
wait(5)
int = true
alive[1].Character.Humanoid.Health = 0
end
hum.Died:Connect(function()
canRoll = true
end)
while true do
wait(0.000001)
for i,v in pairs(workspace.Players:GetChildren()) do
if v:FindFirstChild("Humanoid").Health <= 0 then
v.Parent = workspace.DeadPlayers
end
end
end
while true do
wait(0.000001)
for i,v in pairs(workspace.Players:GetChildren()) do
if v:FindFirstChild("Humanoid").Health <= 0 then
v.Parent = workspace.DeadPlayers
end
end
end
I donât really understand, I need to know what part of this isnât working because its a pretty large script. Anything more specific that is wrong with it, like an error in output?
âA Russian roulette-styled gameâ.
Iâd seriously rethink that since this goes against the Roblox TOS since itâs classed as suicide.
If it isnât a suicide type game then try using prints for troubleshooting before if statements to show you what the variables actually are so you can see why or why not an if reads true.
Also this section only runs once when the script loads:
if int then
gui.Text = "Intermission..."
wait(10)
gui.Text = "Game starting..."
wait(5)
gui.Text = "Game started, good luck..."
wait(3)
round()
wait(2)
db = false
end
local bullets = {"blank", "blank", "blank", "blank", "blank", "live"}
local blanks = 0
local m = game.Players.LocalPlayer:GetMouse()
local hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local livel = 1
local canRoll = true
local canclick = false
local p = game.Players.LocalPlayer
local db = true
local yturn = false
local int = true
local plrs = game.Players:GetChildren()
local selectedp = plrs[math.random(1, #plrs)]
local gui = script.Parent
local intVal = 10
local tool = game.StarterPack.Revolver
local ch = p.CharacterAdded:Wait()
local idle = Instance.new("Animation")
local shoot = Instance.new("Animation")
local roll = Instance.new("Animation")
roll.AnimationId = script.Roll.AnimationId
shoot.AnimationId = script.Shoot.AnimationId
idle.AnimationId = script.Shoot.AnimationId
local trackidle = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Animator:LoadAnimation(idle)
local trackroll = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Animator:LoadAnimation(roll)
local trackshoot = game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Animator:LoadAnimation(shoot)
trackroll.Priority= Enum.AnimationPriority.Action4
local function round()
gui.Text = selectedp.Name.." Gets the gun..."
if selectedp.Name == game.Players.LocalPlayer.Name then
yturn = true
print("Is your turn")
else
yturn = false
end
end
if int then
print("Intermission")
gui.Text = "Intermission..."
wait(10)
print("Game start")
gui.Text = "Game starting..."
wait(5)
print("Game started")
gui.Text = "Game started, good luck..."
wait(3)
print("Round()")
round()
wait(2)
db = false
end
local function shoot()
print("Iniciated shoot function")
wait(3)
local sb = math.random(1, #bullets)
print(sb)
if sb == 6 then
print("Live")
livel -= 1
script.Parent.Text = "There was a bullet, bad luck... There is "..livel.." Bullets left."
hum.Health = 0
else
blanks += 1
print("Blank")
script.Parent.Text = p.Name.." are lucky... There is "..livel.." Bullets left."
end
if blanks == 5 then
sb = 6
end
end
local function click()
print("Click()")
local shootval = 0
shoot()
shootval = shootval + 1
print("Shooted "..shootval.." Times.")
end
m.Button1Up:Connect(function()
print("M1")
if canclick and yturn == true and db == false then
db = true
trackshoot:Play()
trackshoot.Looped = false
script.Parent.Text = selectedp.Name.." Shoot the gun..."
print("Shooted")
click()
yturn = false
wait(5)
local selectedp = plrs[math.random(1, #plrs)]
round()
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
db = false
else
canclick = true
end
end)
if yturn == true then
print("Gived tool")
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true)
end
local alive = workspace.Players:GetChildren()
if #alive <= 1 then
gui.Text = "You are lucky, "..alive.Name.."..."
wait(5)
int = true
end
while true do
wait(0.000001)
for i,v in pairs(workspace.Players:GetChildren()) do
if v:FindFirstChild("Humanoid").Health <= 0 then
v.Parent = workspace.DeadPlayers
end
end
end
while true do
wait(0.000001)
for i,v in pairs(workspace.Players:GetChildren()) do
if v:FindFirstChild("Humanoid").Health <= 0 then
v.Parent = workspace.DeadPlayers
end
end
end
I tried deleting some parts of code but nothing, there is still no prints, no output errors, nothingâŚ
Why do you have the same code twice at the end? And wait(0.000001) isnât relevant. task.wait() should be used, and it can only wait for the next heartbeat (frame) which at 60fps is .016 seconds
If you put a while true do loop in here the rest of your code wonât run.
The way you have this coded itâs looking for players in the Players service where they are stored, not in the workspace (playing the game)
You should use a function that removes/adds players to a table when they leave or join the game.
In another function loop through the table every time a playerâs health changes and see if itâs <= 0 and if it is then add them to .DeadPlayers.
while true do
wait(0.000001)
for i,v in pairs(workspace.Players:GetChildren()) do
if v:FindFirstChild("Humanoid").Health <= 0 then
v.Parent = workspace.DeadPlayers
end
end
end
while true do
wait(0.000001)
for i,v in pairs(workspace.Players:GetChildren()) do
if v:FindFirstChild("Humanoid").Health <= 0 then
v.Parent = workspace.DeadPlayers
end
end
end
How doesnât it answer your question? I pointed out a few issues with your code.
With a while true do loop running in your script the entire script gets stuck inside that loop and none of the other code runs unless you break the loop with some sort of check. Thatâs why you arenât getting anything to work, and you arenât getting any prints.
i think it was other post that i just made with the same issue, but it was becouse a while true do, sorry, misunderstanding, but, theres no loops only 2 at the bottom, so it would not break anything.
Do you get anything printed in the Output window when you test the game?
"but, theres no while âtrue do"s only 2 at the bottom, so it would not break anything.â
First, there is no reason why would you need 2 identical loops at the bottom of the script.
Of course the loop breaks your script. When a script runs it runs top to bottom as soon as the script is loaded. When it gets to a while true do loop itâs going to run just that small loop forever and the rest of the code wonât run, ever.
The only code that should run is the if int then section calling the shoot() function.
The m.Button1Up:Connect(function() section only gets checked the first time the code runs. If the mouse button1up, then it gets bypassed.
Your script now gets to the end and gets stuck in the while true do loop. Since itâs stuck there the mousebutton1up function never gets called, and neither do the other functions.