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

When players teleport swords are not placed in their backpack?

I want the players to receive a weapon when they teleport from the lobby to the map but the output window doesnt give me an error heres the code:

--Giving Weapons to Players
			
			local randomplayers = contestants		
			backpack = game.Players:FindFirstChild("Backpack")
			if randomplayers == killer then
			local sword = repStorage:WaitForChild("Enforcer's Sword"):Clone()
			 sword.Parent = backpack
		elseif  randomplayers ~= killer then
			local weaksword = repStorage:WaitForChild("NonEnforcer"):Clone()
			weaksword.Parent = backpack	
			
		end

2 answers

✓ Accepted answer

Issue here is on line 2, you're calling Backpack through the Players service, which isn't where it sits. You have to grab the player you want to give the items, and grab the Backpack inside of that instance, ex:

local players = game:GetService("Players"):GetPlayers()
local player = players[math.random(1, #players)]
player:WaitForChild("Backpack")
print("Found the backpack in "..player.Name.."!!!")

In this case, it gets a random player from players, and uses :WaitForChild() to pend for the backpack. The result is it would print out "Found the backpack in "- and then would print that player's name.

local players = game:GetService("Players"):GetPlayers()
local killer = math.random(1, #players)

local sword = repStorage:WaitForChild("Enforcer's Sword")
local weaksword = repStorage:WaitForChild("Enforcer's Sword")

for num, player in pairs(players) do
	if (num == killer) then
		sword:Clone().Parent = (player.Backpack) -- this is where you went wrong in the original script
	else
		weaksword:Clone().Parent = (player.Backpack)
	end
end

Hopefully this helped, English is my second language anyhow.

Cheers, HollowMariofan

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