I'm making a cafe game, But my Hand To is not working. I have 2 scripts, 1 script and 1 local script.
LOCAL SCRIPT
local Player = game.Players.LocalPlayer local HandtoGui = script.Parent local NameBox = HandtoGui.NameBox local GiveButton = HandtoGui.GiveButton local groupId = 8513797 local minimumRankToUseGui = 2 if Player:GetRankInGroup(groupId) < minimumRankToUseGui then HandtoGui:Destroy() end local function getPlayerFromPartialName(PartialName) local foundName = nil local Players = game.Players:GetPlayers() for i = 1, Players do local PossiblePlayer = Players[i] if string.find(string.lower(PossiblePlayer.Name), string.lower(PartialName)) then foundName = PossiblePlayer.Name end end if not foundName then return nil else return foundName end end GiveButton.MouseButton1Click:Connect(function() if not Player.Character:FindFirstChildWhichIsA("Tool") then NameBox.Text = "" NameBox.PlaceholderText = "Equip a Tool First!" wait(1) NameBox.PlaceholderText = "Player Name Here" end local NameBoxText = NameBox.Text if NameBoxText ~= "" then local playerName = getPlayerFromPartialName(NameBoxText) if playerName then print("Found player") game.ReplicatedStorage.GivePlayerItem:FireServer(playerName) NameBox.Text = "" NameBox.PlaceholderText = "Gave!" wait(1) NameBox.PlaceholderText = "Player Name Here" else NameBox.Text = "" NameBox.PlaceholderText = "Player Not Found!" wait(1) NameBox.PlaceholderText = "Player Name Here" end end end)
SCRIPT
game.ReplicatedStorage.Events.GivePlayerItem.OnServerEvent:Connect(function(Player, PlayerName) local ToolToGive = Player.Character:FindFirstChildWhichIsA("Tool") ToolToGive.Parent = game.Players[PlayerName].Backpack end)
OUTPUT
Players.memesfordaysa.PlayerGui.HandtoGui.HandTo:16: invalid 'for' limit (number expected, got table)
It something to do with this bit
for i = 1, Players do
But I don't understand.
Use for i = 1, #Players
.
Your error is saying that what i
goes up to needs to be a number, and you gave it the array of players. #Players
will return the length of the game.Players:GetPlayers()
array, which is just how many players are in the array.