imagine using plr.CharacterAdded:Wait()
and then the player leaves, what to do to not make the script crash?
I might be able to help if you send me the script, atleast if you have one.
function MovePeople(P_ONE,P_TWO,P_THREE)
end
function AddToQueue(plr)
if not script.QUEUED:FindFirstChild(""..plr.Name.."") then
local Val = Instance.new("ObjectValue",script.QUEUED)
Val.Name = plr.Name
Val.Value = plr
task.wait()
warn("added "..plr.Name)
if #script.QUEUED:GetChildren() == 2 then
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local First = Plrs[Chosen]
local PLR_ONE = First.Value
First:Destroy()
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local Second = Plrs[Chosen]
local PLR_TWO = Second.Value
local Char_One = PLR_ONE.CharacterAdded:Wait()
local Char_Two = PLR_TWO.CharacterAdded:Wait()
--PLAYER LEFT, HOW TO SOLVE???
MovePeople(Char_One,Char_Two)
end
end
end
my script is not returning any error and not doing anything
The PLR_ONE and the PLR_TWO is only values. Therefore, CharacterAdded:Wait() doesn’t exist.
Simple fix:
function MovePeople(P_ONE,P_TWO,P_THREE)
end
function AddToQueue(plr)
if not script.QUEUED:FindFirstChild(“”…plr.Name…“”) then
local Val = Instance.new(“ObjectValue”,script.QUEUED)
Val.Name = plr.Name
Val.Value = plr
task.wait()
warn("added "..plr.Name)
if #script.QUEUED:GetChildren() == 2 then
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local First = Plrs[Chosen]
local PLR_ONE = game.Players:FindFirstChild(First.Value)
First:Destroy()
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local Second = Plrs[Chosen]
local PLR_TWO = game.Players:FindFirstChild(Second.Value)
local Char_One = PLR_ONE.CharacterAdded:Wait()
local Char_Two = PLR_TWO.CharacterAdded:Wait()
MovePeople(Char_One,Char_Two)
end
end
end
I haven’t tested it, but it should work
the players aint just vvalues. the players
To fix the script crash, I would check if the player is leaving. I would do this:
game.Players.PlayerRemoving:Connect(function(plrLeaving)
if plrLeaving == PLR_ONE or plrLeaving == PLR_TWO then
return
end
end)
what even is “plrleaving”??? charlimitrukle
I suggest you being more specific, but I think you mean the PlayerRemoving function. It checks if a player is leaving and the argument is the player that is leaving.
Edit: Ah, I see what you mean. the plrLeaving argument is what player is leaving
this function… where to put it? inside the main function or whaerrewer
I would put the function at the start of the script, but it depends on what kind of script you’re making.
can i just do this tho?
Showing me the whole script would be much appreciated, but I suppose it might work?
There is no more code. I’m sorry
Hey! If this is not solven already, try this:
function MovePeople(P_ONE,P_TWO,P_THREE)
end
function AddToQueue(plr)
if not script.QUEUED:FindFirstChild(""..plr.Name.."") then
local Val = Instance.new("ObjectValue",script.QUEUED)
Val.Name = plr.Name
Val.Value = plr
task.wait()
warn("added "..plr.Name)
if #script.QUEUED:GetChildren() == 2 then
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local First = Plrs[Chosen]
local PLR_ONE = First.Value
First:Destroy()
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local Second = Plrs[Chosen]
local PLR_TWO = Second.Value
local Char_One = PLR_ONE.CharacterAdded:Wait()
local Char_Two = PLR_TWO.CharacterAdded:Wait()
--PLAYER LEFT, HOW TO SOLVE???
local function onRemoved(PlayerThatLeft)
if PlayerThatLeft == Char_One then
local T1 = script.QUEUED:GetChildren()
local Roll = T1[math.random(1,#T1)]
if Roll ~= Char_Two then
Char_One = Roll
end
elseif PlayerThatLeft == Char_Two then
local T1 = script.QUEUED:GetChildren()
local Roll = T1[math.random(1,#T1)]
if Roll ~= Char_One then
Char_Two = Roll
end
end
end
game:GetService("Players").PlayerRemoving:Connect(onRemoved)
MovePeople(Char_One,Char_Two)
end
end
end
or this:
function MovePeople(P_ONE,P_TWO,P_THREE)
end
function AddToQueue(plr)
if not script.QUEUED:FindFirstChild(""..plr.Name.."") then
local Val = Instance.new("ObjectValue",script.QUEUED)
Val.Name = plr.Name
Val.Value = plr
task.wait()
warn("added "..plr.Name)
if #script.QUEUED:GetChildren() == 2 then
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local First = Plrs[Chosen]
local PLR_ONE = First.Value
First:Destroy()
local Plrs = script.QUEUED:GetChildren()
local Chosen = math.random(1,#Plrs)
local Second = Plrs[Chosen]
local PLR_TWO = Second.Value
local Char_One = PLR_ONE.CharacterAdded:Wait()
local Char_Two = PLR_TWO.CharacterAdded:Wait()
--PLAYER LEFT, HOW TO SOLVE???
if Char_One and Char_Two then
MovePeople(Char_One, Char_Two)
end
end
end
end