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

[UNANSWERED] Why is my item not a valid member of Backpack?

Asked by 6 years ago
Edited 6 years ago

I am making a test game, and I thought you could access backpack items just by calling,

``

   player.Backpack.ITEM

But I guess you can't, because I am getting the error, ``

    10:53:33.764 - Wand is not a valid member of Backpack

Here is my server script that is being called from a localscript when the wand is activated, ``
local repStorage = game:GetService("ReplicatedStorage") local castSpellEvent = repStorage:WaitForChild("CastSpell")

     castSpellEvent.OnServerEvent:connect(function(player, word)
print(word)
if word == "ReFe" then
    local yeet = player:WaitForChild("Backpack")
            print("ReFe FIREWHIP")

    local ray = Ray.new(yeet.Wand.Handle.CFrame.p, 
      yeet.Wand.Handle.CFrame.p.unit * 300)

 local part, position = workspace:FindPartOnRay(ray, player.Character, true, true)
    local beam = Instance.new("Part", workspace)
    beam.Name = "FireWhip"
    local distance = (player.Character.HumanoidRootPart.Position - position).magnitude
    beam.BrickColor = BrickColor.new("Bright red")
    beam.Locked = true
    beam.Anchored = true
    beam.Size = Vector3.new(0.3, 0.3, distance)
    beam.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position,    
             position) * CFrame.new(0, 0, -distance / 2)    




    if part then
    local humanoid = part.Parent:FindFirstChild("Humanoid")

  if not humanoid then
    humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  end

  if humanoid then
    humanoid:TakeDamage(30)
end
 end

end
   end)
0
Sorry for the terrible formatting, I don't really understand how to use the code blocks on here. WorkAtChickenPlace 19 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

When the wand is equipped, it is placed inside the character. You should do:

player.Character:WaitForChild('Wand')

Quick tip: When using the unequip event on a tool, and doing something to the tool, remember to do

player.Backpack.Wand

instead. Put it simply: Only use player.Backpack.Wand when it isn't equipped.

0
WaitforChild isn't a valid member of model WorkAtChickenPlace 19 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Do player.Backpack:WaitForChild("Wand")

0
Thanks for the help, but it says, Infinite yield possible on 'Players.WorkAtChickenPlace.Backpack:WaitForChild("Wand")' WorkAtChickenPlace 19 — 6y
0
That means the wand isn't there Earthkingiv 51 — 6y
0
Then where is it? WorkAtChickenPlace 19 — 6y

Answer this question