Cloning tool to player backpack dont work and weird

im making a script that you can buy a broom for 20$ but it dont work

script.Parent.MouseClick:Connect(function(plr)
	if plr.Backpack:FindFirstChild("Broom") == nil and plr.Character:FindFirstChild("Broom") == nil then
		if plr.leaderstats.Cash.Value >= 20 then
			print("Player Got!")
			plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value - 20
			local broom = game.ReplicatedStorage.Broom:Clone()
			broom.Parent = plr.Backpack
		end
	end
end)

so it prints “Player Got!” but it doesnt go to player backpack and the script in the tool gives an error for the line script.Parent:WaitForChild(“GiveJobPoints”), the tool have GiveJobPoints named instance

1 Like

Is this local or server script?

1 Like

the script in the post is server script

I don’t see any error in your post if it prints…unless the broom isn’t in RepStorage at all. The GiveJobPoints probably is the problem, does it say Infinite Yield possible?

1 Like

the cloning to backpack thing worked in a other script but this script dont work
also the script in the tool gives this error
ReplicatedStorage.Broom.Main:2: attempt to index nil with ‘WaitForChild’

If both scripts are the same, then that means the GiveJobPoints instance doesn’t exist at all at that specific directory. Check its parentage

1 Like

image
it is there
weird thing in an other scripts it works the tool goes to player backpack and you can use the tool

but in this script idk what’s happening it doesnt work it all

You said the script in post is a server script but the script in this one is local…

1 Like

no that’s not the script that’s on the first of the post

image
this is the script that is server script

If it indexes nil with wait for child, then the tool may not have loaded in yet. Tbh idk what’s wrong if it works in other scripts, but just try to wait for the tool

1 Like

i tried that now but the same still happens

At this point you should try rewriting your code in the broom scripts because I’m stumped. There’s theoretically no error if other scripts with the same code work but this one doesn’t

1 Like

yeah im going insane idk what is happening, sorry if i wasted your time thanks for helping!

Nono it’s fine. I’ve got nothing to do either, things like this happen in which it’s best to just scrap the old code or try and make a new instance

1 Like

It’s happening to me too :cry:

My server script named PlayerScript also coded for give tool to a player.
but player’s backpack doesn’t receive cloned tool both Client and Server. I wonder why is this happening, I hope us to get helped.

I can show you guys some lines of scripts, ItemModule also required correctly.

A line of PlayerScript

(ItemModule required correctly)

ItemModule:GiveItem("Boost", Player)
Some lines of ItemModule
local module = {}

function module:GiveItem(ItemName: string, Player: Player)
	if typeof(Player) ~= "Instance" or not Player:IsA("Player") then return end
	if typeof(ItemName) ~= "string" then return end
	
	local Item = module:GetItem(ItemName)
	if Item then
		Item:Clone().Parent = Player.Backpack
		print(Player.Backpack:GetChildren())
	end
end

Also the line print(Player.Backpack:GetChildren()) prints {[1] = Boost} correctly, if i print it again, it suddenly prints empty table.

1 Like

yeah this is so driving me insane