Ad
Log in to vote
0

When i use my local variable in a function, why does it change it for the entire server?

Asked by 21 days ago

Can I pls get some closure? THE PROBLEM IS IN LINE 10

Here is the script:

local Table = {}
local MaxPlayers = 2
local ts = game:GetService("TeleportService")
game.Workspace.Pad1.CanTouch = true
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 0/2"
local inQueue = false

script.Parent.Touched:Connect(function(TouchedPart)
    if TouchedPart.Parent:FindFirstChild("Humanoid") and not inQueue then
        inQueue = true
        local Character = TouchedPart.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        table.insert(Table,Player)
        if #Table < 2 then
            game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 1/2"
            repeat
                wait(0.01)
            until #Table > 1
        else
            if #Table > 1 then
                game.Workspace.TwoPlayerPlayers.Value = 1
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 2/2"
                wait(2)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 10"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 9"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 8"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 7"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 6"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 5"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 4"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 3"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 2"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 1"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING NOW"
                wait(2)
                game.Workspace.TwoPlayerPlayers.Value = 0
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 0/2"
                Table = {}
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by
NykoVania 198 Moderation Voter
21 days ago

Try turning it into a table or maybe putting the variable in the function would work

Script:

local Table = {}
local MaxPlayers = 2
local ts = game:GetService("TeleportService")
game.Workspace.Pad1.CanTouch = true
game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 0/2"

script.Parent.Touched:Connect(function(TouchedPart)
    local inQueue = false
    if TouchedPart.Parent:FindFirstChild("Humanoid") and not inQueue then
        inQueue = true
        local Character = TouchedPart.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        table.insert(Table,Player)
        if #Table < 2 then
            game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 1/2"
            repeat
                wait(0.01)
            until #Table > 1
        else
            if #Table > 1 then
                game.Workspace.TwoPlayerPlayers.Value = 1
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 2/2"
                wait(2)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 10"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 9"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 8"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 7"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 6"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 5"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 4"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 3"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 2"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING IN: 1"
                wait(1)
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "TELEPORTING NOW"
                wait(2)
                game.Workspace.TwoPlayerPlayers.Value = 0
                game.Workspace.TWOPLAYERQUEUE.Overhead.BillboardGui.Frame["PLAYERS&TELEPORTING"].Text = "PLAYERS: 0/2"
                Table = {}
            end
        end
    end
end)
0
I put the variable into the funtion and it addded the player into the table multiple times VictoreRoyale667 8 — 21d
0
Yeah, I realized my error and don't do that lol. Could you explain the issue a little more? NykoVania 198 — 21d
0
It basically makes the variable true for the entire lobby when the function is fired off. VictoreRoyale667 8 — 20d
0
Where is this script located? NykoVania 198 — 20d
Ad

Answer this question