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

Why won't my player appear with the sword more than once?

Asked by 6 years ago

Below is a part of a game script.

There is a value inside player named PersonalSword which carries the string value of the kind of sword that the character will be provided with.

Scheduledsword is the stringvalue of personalsword, which carries the same string value as a sword in ReplicatedStorage.

The problem is I can't get the player to obtain the sword more than once.

On the first time, the script works, but when the second time comes to appear with the sword, I get this message:

"Workspace.GameScript:57: attempt to index local 'scheduledsword' (a nil value)"

function InsertSwords()

    for i, v in pairs(game.Players:GetPlayers()) do
    local playersword = v:WaitForChild("PersonalSword")

    local scheduledsword = game.ReplicatedStorage:FindFirstChild(playersword.Value)


    scheduledsword.Parent = v:WaitForChild("Backpack")


    end
end
0
Did you mean to clone the sword and put the clone in the players' backpack? GoldenPhysics 474 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

You have to clone the sword. If you just simply put the sword in the player's backpack, there will be no sword in ReplicatedStorage to give to the players.

function InsertSwords()

    for i, v in pairs(game.Players:GetPlayers()) do
    local playersword = v:WaitForChild("PersonalSword")

    local scheduledsword = game.ReplicatedStorage:FindFirstChild(playersword.Value):Clone() -- Clones the sword. :)


    scheduledsword.Parent = v:WaitForChild("Backpack")


    end
end

Please accept this as an answer if it helped. Thanks. :)

Ad

Answer this question