For loop only running once

I have already searched the devforum and tried to fix it myself but the for loop only runs once and its supposed to run through all of the players but it only runs through one and gives the apple to one player. (It runs when the player touches a part btw and its in a server script)

local Players = game.Players:GetPlayers()

for i = 1, #Players do
	local player = Players[i]
	print(player)
	Items.Apple:Clone().Parent = player.Backpack
	if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, 2146514245) then
		Items["Alien Portal"]:Clone().Parent = player.Backpack
	end
	if game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, 2146514274) then
		Items.Finality:Clone().Parent = player.Backpack
	end		
end

you should implement it like this:

local Players = game:GetService("Players")

for index, player in pairs(Players:GetPlayers()) do
    print(player.Name, "is found!")
end

by referencing the player variable. you can do what you want to it.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.