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?
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?
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")
Event.OnServerEevnt:Connect(function(player)
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")
end
end)
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
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