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
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
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.
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
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
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,