From what line is the error? It should show where the error was if you click on it.
i think its because its only checking once
error is fixed but the text isnt working
how i can fix that? im new at scripting
The error that the script raised only happens in while loops but make sure to check how many players there are every time a player joins. Use player added event for that
k i will try. But the error is fixed dont think about the error it was a other script
you can just use the playeradded event and add to a value everytime playeradded functions and use an if statement after it
i tried but it dont work
Script:
players = game.Players:GetChildren()
local Text1 = game.Workspace.Text1.SurfaceGui.Text
local Text2 = game.Workspace.Text2.SurfaceGui.Text
Text1.BackgroundTransparency = 1
Text2.BackgroundTransparency = 1
local Players2 = game:GetService(“Players”)
Players2.PlayerAdded:Connect(function(player)
if #players >= 2 then
Text1.Transparency = 1
game.Workspace.Text1.CanCollide = false
Text1.Visible = false
Text2.Visible = true
else
Text1.Visible = true
Text2.Visible = false
Text1.Transparency = 0
game.Workspace.Text1.CanCollide = true
end
if game.ReplicatedStorage.roundover == true then
--coming soon
else
-- coming soon
end
end)
can someone send the full script
Im not sure if this is what you’re looking for but you should try and use what the others said above and structure the script like this.
local Players = game:GetService("Players")
local WS = game:GetService("Workspace")
local TextOneObject = WS:WaitForChild("SurfaceOne")
local TextTwoObject = WS:WaitForChild("SurfaceTwo")
local TextOne = TextOneObject.SurfaceGui.TextLabel
local TextTwo = TextTwoObject.SurfaceGui.TextLabel
function CheckPlayersInServer()
local playersInServer = Players:GetChildren()
TextOne.BackgroundTransparency = 1
TextOne.BackgroundTransparency = 1
if #playersInServer >= 2 then
TextOneObject.Transparency = 1
TextOneObject.CanCollide = false
TextOne.TextTransparency = 1
TextOne.TextTransparency = 0
else
TextOne.TextTransparency = 0
TextOne.TextTransparency = 1
TextOneObject.Transparency = 0
TextOneObject.CanCollide = true
end
end
Players.PlayerAdded:Connect(function(player)
CheckPlayersInServer()
end)
Players.PlayerRemoving:Connect(function(player)
CheckPlayersInServer()
end)
Hope this helps
EDIT: You may need to mess with the code inside the if and else statement
EDIT 2: You may also want to check that the TextOneObject and TextTwoObject are actually found. You could also add a timeout for searching for them in case they’re not in the scene. This should not be the case however as I assume you’re doing this on the server.
its not working i pasted the script
wdym with edit 2. Im not a native speaker
So for this bit you will need to change the string to be the name of your objects
local TextOneObject = WS:WaitForChild("SurfaceOne")
local TextTwoObject = WS:WaitForChild("SurfaceTwo")
And for the EDIT 2, sometimes you might not want waitforchild to go for extended periods of time. Therefore you can add a timeout in the second parameter for WaitForChild() E.g.
local object = objectToGetChildFrom:WaitForChild("ObjectToFind", timeout)
if object then
--The object was found and did not return nil
end
There is also FindFirstChild() which will return nil if it cant find the object. This is instead of waiting for it to exist.
local object = objectToGetChildFrom:FindFirstChild("ObjectToFind")
if object then
--The object was found and did not return nil
end
thanks, but idk exactly how i can use it. Im really new at scripting, can you send me the working script maybe with explainings?
Okay, give this a go. Not sure if it will work straight away though.
local Players = game:GetService("Players")
local WS = game:GetService("Workspace")
--Getting Objects that hold the surface GUI's
local TextOneObject = WS:WaitForChild("Text1")
local TextTwoObject = WS:WaitForChild("Text2")
--Getting the Surface GUI Text
local TextOne = TextOneObject.SurfaceGui.Text
local TextTwo = TextTwoObject.SurfaceGui.Text
function CheckPlayersInServer()
local playersInServer = Players:GetChildren() --Gets Players in server
--Resets Objects Transparency
TextOne.BackgroundTransparency = 1
TextOne.BackgroundTransparency = 1
--Changes Object and Gui Properties based on player count
if #playersInServer >= 2 then
TextOneObject.Transparency = 1 --May Need Changing for your purpose
TextOneObject.CanCollide = false --May Need Changing for your purpose
TextOne.TextTransparency = 1 --May Need Changing for your purpose
TextOne.TextTransparency = 0 --May Need Changing for your purpose
else
TextOne.TextTransparency = 0 --May Need Changing for your purpose
TextOne.TextTransparency = 1 --May Need Changing for your purpose
TextOneObject.Transparency = 0 --May Need Changing for your purpose
TextOneObject.CanCollide = true --May Need Changing for your purpose
end
end
Players.PlayerAdded:Connect(function(player) --When a player Joins
CheckPlayersInServer() --Runs the Check Function
end)
Players.PlayerRemoving:Connect(function(player) --When a player Leaves
CheckPlayersInServer() --Runs the Check Function
end)
no its not working too dffd
What’s not working?. Does it throw an error or is it just not functioning correctly? in which case is one of the objects disappearing and not the other?
its now working i did a spelling mistake.
Awesome
Good Luck with your project , enjoy your day.
tysm. erdrerreererrerererererre