Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Trouble Adding Tool to Player Backpack. Any Solutions?

Asked by 2 years ago

Hey all I'm figuring out the systems that are needed in place for this farming game im making and so im having trouble with this script on getting seeds into the player's inventory when they harvest whatever plant they are growing. I've tried many solutions, but they wouldn't work. Script looks kinda bad but lemme know if you have a solution to this!

Keep in mind, this is on a regular script so im not sure if i should use a LocalScript for this.

Thanks!

local plantPart = script.Parent
local ClickDetector = script.Parent:FindFirstChild("ClickDetector")
wait(3)
plantPart.Size = Vector3.new(4,2,4)
wait(3)
plantPart.Size = Vector3.new(4,3,4)
wait(3)
plantPart.Size = Vector3.new(4,4,4)
wait(3)
plantPart.Size = Vector3.new(4,5,4)

if plantPart.Size == Vector3.new(4,5,4) then
    print("Ready to Harvest!")
    ClickDetector.MouseClick:Connect(function(player)
        plantPart:Destroy()
        if plantPart:Destroy() or plantPart.Size == Vector3.new(4,5,4) then
            local Money = player.leaderstats.Money
            Money.Value = Money.Value + 5

            local PlayerSeeds = game:GetService("ReplicatedStorage").Seeds:Clone()
            local PlayerInv = game:GetService("StarterPack")
            PlayerSeeds.Parent = PlayerInv
        end
    end)

end

1 answer

Log in to vote
0
Answered by
ultrabug 306 Moderation Voter
2 years ago
Edited 2 years ago

Is the "seeds" thing you are trying to give the player a tool? If it isn't I don't think it will show up in the player's default backpack. If it is a tool, then your issue might be that you are putting it into starterpack, which will give the tool to every player, but only when their character respawns. If you just want to give it to one player you can put it in the player's startergear and they will get it when they respawn, or you can put it in their backpack and they will get it immediately, but won't keep it if they respawn.

Edit: I made this in my own place and it appears to do what you want. I think you might just have missed that the mouseclick event gives you the player that clicked so you can just put it right in their backpack from there.

local cd = script.Parent.ClickDetector
local tool = game:GetService("ReplicatedStorage").Tool

cd.MouseClick:Connect(function(player)
    local newtool = tool:Clone()
    newtool.Parent = player.Backpack
end)
1
Yes the seeds object is indeed a tool, its supposed to get put into the backpack when the player harvests a plant when its big enough. The trouble is that i don't have a proper solution as to how to reference the backpart part of the player correctly. Astrosupernuat 29 — 2y
0
backpack is a descendent of player, and you are getting player from the clickdetector function so you could just do PlayerSeeds.Parent = player.Backpack ultrabug 306 — 2y
0
Holy cow, it works. Thx a lot! Astrosupernuat 29 — 2y
0
yep ultrabug 306 — 2y
Ad

Answer this question