Hi guys,
so I've been messing around with this script for a bit now and I'm just so confused! The idea is that when a user joins it creates a BoolValue, changes the parent to the player in game.Players, and goes on false by default.
This all works fine, no issues there, until I get to the part where it should CHECK if the user is wanted by using a while loop.
Here's my code:
game.Players.PlayerAdded:Connect(function(p)
local bool = Instance.new("BoolValue") --Creates new BoolValue for players
bool.Parent = p
bool.Name = "Wanted"
bool.Value = false
p.CharacterAdded:Connect(function(char)
function checkwanted()
while wait(1) do
if bool.Value == true then
if char.Head:FindFirstChild("wanted") then
char.Head:FindFirstChild("wanted"):Destroy()
else
local gui = script:FindFirstChild("wanted"):Clone()
gui.Parent = char.Head
gui.Enabled = true
end
elseif bool.Value == false then
if char.Head:FindFirstChild("wanted") then
char.Head:FindFirstChild("wanted"):Destroy()
end
end
end
end
checkwanted()
end)
end)
Now you might've guessed it already, what I'm trying to do is make sure the loop checks if the user is wanted every second. If he is, it checks if the user already has a GUI. When he does, it removes the GUI to prevent multiple GUIs in the character's head. The issues is, and I am well aware, that the while loop adds and creates a new GUI every second because it detects a GUI already. This is incredibly annoying, and I know no other way to stop this!
Do you guys have any suggestions for me? I cannot seem to figure a way out to make sure it checks if the user has a GUI already and then stops, but STILL checks if the user's value is false to permanently remove the GUI

1 comment
Works like a charm! Much appreciated :) I'll look into those Clients, and the Changed event is a savior.