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
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?
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 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
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
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.