Wood Block Rewarder Isn't Working

Hello! So Im trying to make a Minecraft test demo type game to test my scripting skills, this part isnt working though.

  09:46:03.667  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:03.667  Stack Begin  -  Studio
  09:46:03.668  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:03.668  Stack End  -  Studio
  09:46:05.116  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:05.116  Stack Begin  -  Studio
  09:46:05.116  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:05.116  Stack End  -  Studio
  09:46:06.432  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:06.432  Stack Begin  -  Studio
  09:46:06.432  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:06.432  Stack End  -  Studio
  09:46:07.066  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:07.067  Stack Begin  -  Studio
  09:46:07.067  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:07.067  Stack End  -  Studio
  09:46:07.316  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:07.316  Stack Begin  -  Studio
  09:46:07.316  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:07.316  Stack End  -  Studio
  09:46:07.331  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:07.332  Stack Begin  -  Studio
  09:46:07.332  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:07.332  Stack End  -  Studio
  09:46:09.166  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:09.166  Stack Begin  -  Studio
  09:46:09.166  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:09.167  Stack End  -  Studio
  09:46:18.115  Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript:13: attempt to index nil with 'Backpack'  -  Client - LocalScript:13
  09:46:18.115  Stack Begin  -  Studio
  09:46:18.116  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  09:46:18.116  Stack End  -  Studio

Here is the Script that is supposed to break things and award a block

script.Parent.Touched:connect(function(hit)
	if hit ~= nil then
		local block = hit.Parent
		if block ~= nil then
			local humanoid = block:FindFirstChild("Humanoid")
			if humanoid ~= nil then
				wait(3.5)
				block:Destroy()
				humanoid:Destroy()
				if block.Name == "WoodBlock" then
					local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
					local BlockTool = game.ReplicatedStorage.Wood_Block:Clone()
					BlockTool.Parent = plr.Backpack
				end
			end
		end
	end
end)
1 Like

I’m pretty sure GetPlayersFromCharacter() returns nil if something that’s not a player character gets passed through, so maybe try checking if the plr variable is nil after you call the function.

1 Like

hit.Parent means block, right?

do this instead:

local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent)

-- when the tool is being equipped it will be in the player's character

since the script is in the tool then script.Parent.Parent.Parent means player

yes it does mean the block


then you shouldn’t do like game.Players:GetPlayerFromCharacter(hit.Parent) since it’s the same thing (you’re trying to get a player from the block)

1 Like

do what I said to fix this problem

2 Likes

Do you have a local script in workspace?

lol I forgot when the tool is being equipped then the tool will be in the player’s character

Didnt work

  12:33:56.160  Backpack is not a valid member of Model "Workspace.NubblyFry"  -  Client - LocalScript:13
  12:33:56.160  Stack Begin  -  Studio
  12:33:56.161  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  12:33:56.161  Stack End  -  Studio
  12:33:56.162  Backpack is not a valid member of Model "Workspace.NubblyFry"  -  Client - LocalScript:13
  12:33:56.162  Stack Begin  -  Studio
  12:33:56.162  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  12:33:56.163  Stack End  -  Studio
  12:34:04.507  Backpack is not a valid member of Model "Workspace.NubblyFry"  -  Client - LocalScript:13
  12:34:04.507  Stack Begin  -  Studio
  12:34:04.507  Script 'Workspace.NubblyFry.Wooden Pickaxe.TopPart.LocalScript', Line 13  -  Studio - LocalScript:13
  12:34:04.507  Stack End  -  Studio

Also I changed the script to this,

script.Parent.Touched:connect(function(hit)
	if hit ~= nil then
		local block = hit.Parent
		if block ~= nil then
			local humanoid = block:FindFirstChild("Humanoid")
			if humanoid ~= nil then
				if block.Name == "WoodBlock" then
					wait(3.5)
					block:Destroy()
					humanoid:Destroy()
					local plr = script.Parent.Parent.Parent
					local BlockTool = game.ReplicatedStorage.Wood_Block:Clone()
					BlockTool.Parent = plr.Backpack
				else
					if block.Name == "LeafBlock" then
						wait(0.5)
						block:Destroy()
						humanoid:Destroy()
					end
				end
			end
		end
	end
end)

One thing to note is that Im doing this all in a Local Script

you can also get the player by using
local plr = game.Players.LocalPlayer
not need to :GetPlayerFromCharacter

1 Like

It works! Thanks!


thanks!!! this was my first solution! im so happy

1 Like