Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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}

1 comment

0

Thanks! I see now.

This discussion is preserved as it was. New answers, comments, and votes are closed.