I have this script someone helped me with but I am trying to use == and >= and it is not working but when I use <= it works
here is my script:
local numplayers = #game.Players:GetChildren() while true do if numplayers <= 2 then for i,v in pairs(game.Players:GetPlayers()) do part = game.Workspace.Folder["Part".. tostring(i)] local hrp = v.Character.HumanoidRootPart hrp.CFrame = CFrame.new(part.Position + Vector3.new(0,5,0)) end end wait(45) end
Wrote this directly on the website, so the code may or may not function as intended.
It could be because you did not update numplayers
, and therefore it stays the same no matter if players join or quit. You can up and down the counter whenever a player leaves or joins, so that the value actually updates.
You should also avoid using while loops. One of many ways to go around this is to tween a value from 0 to 45, and whenever the tween finishes the wait should be over. Then you set the value back to 0 and tween it to 45 again.
Also some minor changes, such as checking if a player’s character actually exists before applying changes to the HumanoidRootPart
.
local Players = game:GetService('Players') local TweenService = game:GetService('TweenService') local countdownValue = Instance.new('IntValue') local playerAmount = 0 local countdownTween = TweenService:Create(countdownValue, TweenInfo.new(45), {Value = 45}) Players.PlayerAdded:Connect(function() playerAmount += 1 end) Players.PlayerRemoving:Connect(function() playerAmount -= 1 end) countdownTween:Play() countdownTween.Completed:Connect(function() if playerAmount <= 2 then for i, player in ipairs(Players:GetPlayers()) do local character = player.Character if character then character.HumanoidRootPart.CFrame = CFrame.new(workspace.Folder['Part']..tostring(i)] + Vector3.new(0, 5, 0)) end end end countdownValue.Value = 0 countdownTween:Play() end)