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

Trying to make a gun spawner script but script can't find player?

Asked by 3 years ago

I'm creating a script that simply looks for the player's userids, what guns there allowed to spawn, and how many spawns they have left. The script seems to stop reading things correctly past if table.find(owners, plr.UserId) then which is that part that looks for the players userid.

local adminguns = {"G26L","G17"}
local owners = {"46315828"}
local amount = 10
game.Players.playerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(message)
        print("plrchat")
        if message and string.sub(message, 1, 7):lower() == "/spawn " then
            print("plrsaidspawn")
            if table.find(owners, plr.UserId) then
                print("plrfound")
                if table.find(adminguns, string.sub(message, 7)) then
                    print("admingunfound")
                    if amount > 0 then
                        print("amountmorethanzero")
                        local firearms = game.ServerStorage.Assets:WaitForChild("Firearms")
                        if firearms:FindFirstChild(string.sub(message, 7)) ~= nil then
                            print("weaponnotnil")
                            local spawn = firearms:FindFirstChild(string.sub(message, 7)):Clone()
                            spawn.Parent = plr.Backpack
                            amount = (amount - 1)
                            print("worked!")

                        end
                    end
                    end
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You're finding a number (plr.UserId) in a table with string, which is why it won't work. You'll have to turn the user id to a string, or replace the string in table with a number. You can turn the user id to the string, use tostring(plr.UserId)

            if table.find(owners, tostring(plr.UserId)) then

or you can just make the string in table a number

local owners = {46315828}
0
Thanks! I see now. DogCooper 2 — 3y
Ad

Answer this question