Trouble giving tool to player

I am making a tool shop gui for my obby to try to keep players active and so far I got enough help to figure out how to take the cash before I went to sleep. I am now having trouble cloning the tool and finding the players backpack. Can someone point out anything wrong?



I am new to server events and just scripting in general so I not very good at this.

The error seems to arise from the fact that you’re assigning FindFirstChild to nothing. You should be doing this instead:

local pack = game.Players.LocalPlayer:FindFirstChild("Backpack")
if pack then
     print("backpack found")

Please tell me if that fixed your problem.

1 Like

doesnt seem to fix it

This is because you can’t use .LocalPlayer on the server since the server covers all players in game

remove game.Players.LocalPlayer in the script with player

1 Like

Yeah, sorry, I didn’t notice that was a serverscript. LocalPlayer doesn’t work in the server at all. Have you tried using the player parameter passed from the remote?

1 Like

Im not sure how to do that. I havent used that before I think.

Right here, you passed a player object from the remote. This is referencing the player that called the remote.

Instead of using game.Players.LocalPlayer, replace it with just player.

1 Like

Thanks alot I always thought that was just the name for a function. I didnt know it actually ment something! It worked.

Also can you tell me why the tool wont clone? I cant figure that out either. Thanks for all your help.

The problem is that you are getting the LocalPlayer in a Server Script. LocalPlayer can only be accessed on a LocalScript.

Try using this code for your Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")

local Event = ReplicatedStorage:WaitForChild("TakeCashFartGun")
local FartGun = Lighting:WaitForChild("FartRevolver")

   if player.leaderstats.Coins.Value >= 1250 then
      player.leaderstats.Coins.Value -= 1250
      local CloneFartGun = FartGun:Clone() -- clones fart revolver
      CloneFartGun.Parent = player.Backpack -- then places the cloned gun in the player's backpack
      print("gun parented to player's backpack")
1 Like

Thanks that worked. People on here are a big help

1 Like

It is cloning, you’re just not setting its parent to the player’s backpack.

local sss = game:GetService("ServerScriptService")
local tool = sss:FindFirstChild("testtool")
local plr = game.Players.plr1
-- plr here is just a test, your script would
-- just use the player passed from the remote

local cln = tool:Clone()
cln.Parent = plr.Backpack

Also, why are you storing a tool in lighting?

1 Like

Thanks. I dont know why I put in in lighting. I just see other people do it.

Its best if you place your tool in ReplicatedStorage (or even ServerStorage). I also see people putting their tools in Lighting, but I dont understand why… lol

1 Like