Why the tool script won't working when its parented to workspace?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Why does the tool script won’t work when the tool is parented to the workspace? but worked when the tool parented to StarterPack.

  2. What is the issue? Include screenshots / videos if possible!
    Error.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I Tried WaitForChild()
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local tool = script.Parent
local scoop = tool.Scoop
 
local backpack = tool.Parent
local player = backpack.Parent
local playerStats = player:WaitForChild("leaderstats")
local playerItems = playerStats:WaitForChild("Items")
local playerSpaces = playerStats:WaitForChild("Spaces")
 
local function onTouch(partTouched)
	local canHarvest = partTouched.Parent:FindFirstChild("CanHarvest")
	if canHarvest then
		if canHarvest.Value == true and playerItems.Value < playerSpaces.Value then
			playerItems.Value = playerItems.Value + 1
			canHarvest.Value = false
			partTouched.Transparency = 1 
			partTouched.CanCollide = false
			wait(5)
			canHarvest.Value = true
			partTouched.Transparency = 0 
			partTouched.CanCollide = true
 
		end
	end
end
 
scoop.Touched:Connect(onTouch)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The script assumes that the parent of the tool is the backpack hence it will break if the tool is in the workspace as it cannot obtained the player.

To solve this obtain the player instance when the tool is equipped as it’s guaranteed the tool will be parented under the character model. Then you can use Players:GetPlayerFromCharacter to obtain the player instance which the script needs.

so how do I replace tool.Parent with Players:GetPlayerFromCharacter()