Im making a town-rpg game something like generic roleplay gaem and a wanted system for the game. Basically when a player comitted a crime, i want them to become wanted for a while. It’s working well when i tested by myself but in team test, it only works for the first player who increased “WantedTime” intvalue
local folder = game.ReplicatedStorage.MoreStuffs
local functionrunning = false
local humanoiddied = false
local function wantedazaltma(wantedtime)
print("function 1")
if humanoiddied == true then
print("return 1")
humanoiddied = false
functionrunning = false
return
end
if wantedtime then
if humanoiddied == true then
print("return 2")
humanoiddied = false
functionrunning = false
return
end
end
while wantedtime.Value > 0 do
if humanoiddied == true then
humanoiddied = false
functionrunning = false
print("return 3")
return
end
if wantedtime then
wait(1)
print("while")
wantedtime.Value -= 1
end
end
functionrunning = false
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
humanoiddied = false
print("char added")
local wantedbillboard = folder.WantedBillboard:Clone()
wantedbillboard.Parent = char:WaitForChild("Head")
local wantedbool = Instance.new("BoolValue")
wantedbool.Value = false
wantedbool.Name = "WantedBool"
wantedbool.Parent = char
local wantedtime = Instance.new("IntValue")
wantedtime.Value = 0
wantedtime.Name = "WantedTime"
wantedtime.Parent = char
local connectionazaltma
local function wantedtimechanged()
if wantedtime.Value < 0 then
wantedtime.Value = 0
wantedbool.Value = false
elseif wantedtime.Value == 0 then
wantedbool.Value = false
elseif wantedtime.Value > 0 then
wantedbool.Value = true
if functionrunning == false then
functionrunning = true
spawn(function()
print("spawn")
wantedazaltma(wantedtime)
end)
end
end
if wantedtime.Value > 0 and wantedtime.Value <= 240 then
wantedbillboard.TextLabel.Text = "★"
elseif wantedtime.Value > 240 and wantedtime.Value <= 480 then
wantedbillboard.TextLabel.Text = "★★"
elseif wantedtime.Value > 480 and wantedtime.Value <= 720 then
wantedbillboard.TextLabel.Text = "★★★"
elseif wantedtime.Value > 720 and wantedtime.Value <= 960 then
wantedbillboard.TextLabel.Text = "★★★★"
elseif wantedtime.Value > 960 then
wantedbillboard.TextLabel.Text = "★★★★★"
end
end
local wantedtimeconnect = wantedtime.Changed:Connect(wantedtimechanged)
local function wantedboolchanged()
if wantedbool.Value == true then
wantedbillboard.Enabled = true
else
wantedbillboard.Enabled = false
end
end
local wantedboolconnect = wantedbool.Changed:Connect(wantedboolchanged)
local hum = char:FindFirstChild("Humanoid")
hum.Died:Connect(function()
humanoiddied = true
wantedtimeconnect:Disconnect()
end)
end)
end)
```.