Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with this script of mine?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

This is my peace of code I am trying, to make the team 'Test' Removed When 1 Player enters the game but there is an Error for it.

while true do
    if game.Players.NumPlayers == 1
then game.Teams.Test:remove
    end -- This one says "function arguments expected near 'end' "
end

Anyone able to explain this to me?

2 answers

Log in to vote
1
Answered by
Destrings 406 Moderation Voter
10 years ago

First of all, that piece of code would crash the game because you are not allowing the thread scheduler to move on with other threads. You need to add wait() to yield the current thread so the game knows it can move on with other actions.

The error tells you that the interpreter was expecting a function call. Remove is a method you are not calling. Also, Remove is deprecated, consider using Destroy instead.

while wait() do --We add a call to wait to yield the thread
    if game.Players.NumPlayers == 1 then
        game.Teams.Test:Destroy() --We call the method with ()
    end
end

Consider optimizing your code, since you would be running an infinite loop and wasting resources on something that can be solved with events.

I am trying to make the team 'Test' Removed when 1 Player enters the game.

game.Players.PlayerAdded:connect(function()
    game.Teams.Test:Destroy()
end)
Ad
Log in to vote
-2
Answered by 10 years ago

you need a function loop

function nameofcodehere() 
if game.Players.NumPlayers == 1 then
game.Teams.Test:remove() -- or Destroy()
          end
end

Answer this question