You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
return the first value when the condition is met
What is the issue? Include screenshots / videos if possible!
the value is not returning although the condition is met
local players = game:GetService('Players')
local event = game:GetService("ReplicatedStorage").events.spawncharacter
local peoplefolder = game.Workspace.CompassPeople:GetChildren()
players.PlayerAdded:Connect(function(plr)
local boolvalue = Instance.new("BoolValue")
local boolvalue2 = Instance.new("BoolValue")
boolvalue2.Value = false
boolvalue.Value = false
boolvalue.Name = "playerisnear"
boolvalue2.Name = "playerplacedcharacter"
boolvalue2.Parent = plr
boolvalue.Parent = plr
end)
local function characterloaded(PlayerName:string?)
for _,v in peoplefolder do
if tostring(v):match(PlayerName) then
return true
end
end
return false
end
event.OnServerEvent:Connect(function(player,mousepos,mousetarget)
print(player.Name)
if characterloaded(player.Name) == false and mousetarget.Name == "PlayerTile" and player:WaitForChild("playerplacedcharacter").Value == false then
player:WaitForChild("playerplacedcharacter").Value = true
print("it is false")
print(mousepos)
local charactercopy = game.Players:CreateHumanoidModelFromUserId(player.UserId)
charactercopy.Name = player.Name
charactercopy.Parent = game.Workspace.CompassPeople
charactercopy.PrimaryPart.CFrame = mousepos + (charactercopy.PrimaryPart.CFrame).LookVector + Vector3.new(0,4,0)
elseif characterloaded(player.Name) == true and mousetarget.Name == "PlayerTile" and player:WaitForChild("playerplacedcharacter").Value == true then
print("it is true")
end
end)
local function CharacterLoaded(PlayerName:string?)
for _,v in peoplefolder do
if tostring(v):match(PlayerName) then
return true
end
end
return false
end
local function CharacterLoaded(PlayerName:string?)
for _,v in peoplefolder do
if tostring(v):match(tostring(PlayerName)) then
return true
end
end
return false
end
Actually just use this, it converts everything to a string so it works. Because I would assume PlayerName isn’t a string. Additionally you can use this. print(type(PlayerName))
local function CharacterLoaded(PlayerName:string?)
print(type(PlayerName))
for _,v in peoplefolder do
print(type(v))
if tostring(v):match(tostring(PlayerName)) then
return true
end
end
return false
end
PeopleFolder will only run ONCE. Meaning you will only have the old default folder and not any updated folder.
local function characterloaded(PlayerName:string?)
for _,v in game.Workspace.CompassPeople:GetChildren() do
if tostring(v):match(PlayerName) then
return true
end
end
return false
end