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
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. :)