Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When players teleport swords are not placed in their backpack?

Asked by 8 years ago

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

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

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

Ad
Log in to vote
0
Answered by 8 years ago

try putting the swords in Lighting and cloning them out of there.

0
That didnt work TheTopBoss -2 — 8y
0
and output gives nothing? shasta342 37 — 8y
0
nope TheTopBoss -2 — 8y

Answer this question