Give Item Script not working

Hey.

I got back from 2 months of not scripting, so I may have forgot some lines. I’m currently making a script that gives a sword to everybody in the server, but it doesn’t work. I tried to fix it, but I don’t see the problem. Help is appreciated!

local ServerStorage = game:GetService("ServerStorage")

local BasicSword = ServerStorage["Basic Sword"]

for i, player in pairs(Players) do
	local CloneBasic = BasicSword:Clone()
	CloneBasic.Parent = player.Backpack
end

I think you missed a couple of lines here image

Better yet, you can create a PlayerAdded Event so that it fires every time a Player joins the game if that’s what you want? Otherwise you can just do this:

local ServerStorage = game:GetService("ServerStorage")
local BasicSword = ServerStorage["Basic Sword"]
local Players = game.Players:GetPlayers()

for i, player in pairs(Players) do
	local CloneBasic = BasicSword:Clone()
	CloneBasic.Parent = player.Backpack
end
1 Like

No, it’s a round based game so I want to do it at a certain point, and there was a player variable, I didnt include it in the script I showed.

Well I’ll ask this then:

  • What type of script is it? Server or Local?

  • Where is it located?

  • Are you getting any errors on the Output at all?

1 Like

Are you spelling the name correctly? check the name and location of the tool in your server storage and see if you’re declaring its location in the script correctly.

1 Like

Server
ServerScriptService

No errors at all.

The spelling is correct, I’ve checked.

I’d recommend just checking for print statements then

There could be the possibility that you’re calling the GetPlayers() function too early, which would return back nothing since no players have loaded in time when it was first called in from

Do you have any for loops above this one? maybe that’s preventing this from running.

Yeah, it teleports players to a brick.

I switched the teleportation and give item loop, nothing’s still working. I also moved the player variable to when the round starts, nothing. My full script if you need it:

local ReplicatedService = game:GetService("ReplicatedStorage")
local Status = ReplicatedService.Status

local ServerStorage = game:GetService("ServerStorage")

local BasicSword = ServerStorage["Basic Sword"]

local minutes = 120

while true do
	
		Status.Value = "Waiting for 4 players..."
		wait(1)
	repeat wait() until game.Players.NumPlayers >= 1
	
	repeat
		minutes = minutes - 1
		Status.Value = minutes
		wait(1)
	until minutes == 0
	
	local function TeleportTeamPlayers(teamspawn,teamcolor)
	for i,player in pairs(game:GetService("Players"):GetPlayers())do
				if player.TeamColor == teamcolor then
			   player.Character.HumanoidRootPart.CFrame = teamspawn.CFrame
			end
		end
	end
	TeleportTeamPlayers(workspace.BluePart, BrickColor.new("Really blue"))
	TeleportTeamPlayers(workspace.RedPart, BrickColor.new("Really red"))
	wait(1)
	Status.Value = "Round will start in..."
	wait(1)
	Status.Value = "5"
	wait(1)
	Status.Value = "4"
	wait(1)
	Status.Value = "3"
	wait(1)
	Status.Value = "2"
	wait(1)
	Status.Value = "1"
	wait(1)
	
	minutes = 300
	
	local Players = game.Players:GetPlayers()
	
	for i, player in pairs(Players) do
		local CloneBasic = BasicSword:Clone()
		CloneBasic.Parent = player.Backpack
	end
end

repeat
	minutes = minutes - 1
	Status.Value = minutes
	wait(1)
until minutes == 0

Try this

local ReplicatedService = game:GetService("ReplicatedStorage")
local Status = ReplicatedService.Status

local ServerStorage = game:GetService("ServerStorage")

local BasicSword = ServerStorage["Basic Sword"]

local minutes = 6


while true do

   Status.Value = "Waiting for 4 players..."
   wait(1)
   repeat wait() until game.Players.NumPlayers >= 1

   local function TeleportTeamPlayers(teamspawn,teamcolor)
   	for i,player in pairs(game:GetService("Players"):GetPlayers())do
   		if player.TeamColor == teamcolor then
   			player.Character.HumanoidRootPart.CFrame = teamspawn.CFrame
   		end
   	end
   end
   TeleportTeamPlayers(workspace.BluePart, BrickColor.new("Really blue"))
   TeleportTeamPlayers(workspace.RedPart, BrickColor.new("Really red"))
   wait(1)
   Status.Value = "Round will start in..."
   wait(1)
   Status.Value = "5"
   wait(1)
   Status.Value = "4"
   wait(1)
   Status.Value = "3"
   wait(1)
   Status.Value = "2"
   wait(1)
   Status.Value = "1"
   wait(1)


   local Players = game.Players:GetPlayers()

   for i, player in pairs(Players) do
   	local CloneBasic = BasicSword:Clone()
   	CloneBasic.Parent = player.Backpack
   end
end

repeat
   minutes = minutes - 1
   Status.Value = minutes
   wait(1)
until minutes <= 0

The reason mainly the loop didn’t work is because you had an unnecessary loop,

1 Like

local ServerStorage = game:GetService(“ServerStorage”)

local Players = game:GetService(“Players”)

local BasicSword = ServerStorage:WaitForChild(“Basic Sword”)

for i,Player in pairs(Players:GetPlayers()) do
local CloneBasic = BasicSword:Clone()
CloneBasic.Parent = player:WaitForChild(“Backpack”)
end

1 Like