Can You Not Use FindFirstChild in a Collectable Coin

I have this script in an item in Replicated Storage. Basically when the player collects a coin the value of the coin gets multiplied by the multiplier a player has (Similar to a lot a simulators). The multiplier is an IntValue located in StarterGui. I’m not sure find to get the players multiplier.

14:22:35.554 - Workspace.ElixirDrop.ElixirDropCollect:4: attempt to index nil with ‘Name’

local elixir = script.Parent
local currency = "Elixir" -- rename to the currency that you want to use
local amt = 1 -- How many coins the player gets
local upgrades = game.Players:FindFirstChild(player.Name).PlayerGui.ScreenGui2.Upgrade.Cost.Cost:WaitForChild('UpgradesIntValue')

local d = true

elixir.Touched:Connect(function(p)
  if p.Parent:FindFirstChild("Humanoid") and d then
     d = false

    local plr = game.Players:FindFirstChild(p.Parent.Name)

    plr:FindFirstChild("leaderstats"):FindFirstChild(currency).Value =  plr:FindFirstChild("leaderstats"):FindFirstChild(currency).Value + amt*upgrades.Value

    elixir:Destroy()
  end
end)

It seems like you haven’t defined player in line 4

1 Like