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

Why is my script skipping "if PlayersInTable[player] do"?

Asked by 3 years ago

I've asked tons of people to get up to this point (most of the answers didn't work)

This is my script now:

print("script started")


local part = script.Parent
local Amount = script.Parent.Parent.Space1.SurfaceGui.Amount
local TPService  = game:GetService("TeleportService")
print("locals 1 started")

local PlayerInTable = {}

local PlayersToTeleport = {PlayerInTable}

local player = game.Players.LocalPlayer

Amount.Text = "0/6"

local counter = 0

local debounce = false
print("all locals started")


part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local character = hit.Parent
        local players = game.Players:GetPlayerFromCharacter(character)
        table.insert(PlayerInTable, players)
        print("player is in PlayerTable")
    end

    if PlayerInTable[player] then
        print("player table script running")
        counter = counter + 1
        Amount.Text = counter.. "/6"
        wait(1) --// debounce timeout
        debounce[player] = true
        print(player.Name.. " is in table")
    else
        debounce = false
        print("player not in table")
    end
     end)

But here is the problem:

if PlayerInTable[player] then
        print("player table script running")
        counter = counter + 1
        Amount.Text = counter.. "/6"
        wait(1) --// debounce timeout
        debounce[player] = true
        print(player.Name.. " is in table")
    else
        debounce = false
        print("player not in table")
    end
     end)

but goes right to the else and prints "player not in table" why?

(most people I ask just ignore me and they dont know either soo..)

0
Is this a LocalScript? And if so, what is the LocalScript's parent? deeskaalstickman649 475 — 3y
0
Its not a LocalScript Magicalsuperlily914 15 — 3y
0
game.Players.LocalPlayer is a read-only property that is locally set to the player instance of the client. However, the property is set only on the client side. This is because on the server, there will never be a client, and therefore the LocalPlayer property will always be set to nil on the server. deeskaalstickman649 475 — 3y
0
I mean that does make sense Magicalsuperlily914 15 — 3y
View all comments (2 more)
0
What should I do instead Magicalsuperlily914 15 — 3y
0
I suggest using a for i, v in pairs() loop to check if player has been inserted into PlayerInTable. deeskaalstickman649 475 — 3y

Answer this question