Im trying to create a wood gathering script but i get the error that i mentioned at title. my code is here:
local Plr= game.Players.LocalPlayer
local Char = Plr.Character
local Mouse = Plr:GetMouse()
local GetWood = true
function ShowProgress(tree)
if tree == 'Tree' then
for i = 0,1, .01 do
WG.BG.Bar.Progress.Size = UDim2.new(i,0,1,0)
wait()
end
end
end
Mouse.Button1Down:connect(function()
if Mouse.Target ~= nil and Mouse.Target.Parent.Name == 'Tree' and GetWood == true then
local Wood = Mouse.Target
if (Wood.Position - Char.HumanoidRootPart.Position).magnitude <10 then
GetWood = false
WG = Plr.PlayerGui.WoodGathering
WG.BG.Visible = true
Char.Humanoid.WalkSpeed = 0
for i, v in pairs(Wood.Parent.Leaves:GetChildren())do
if v:IsA('Part') then
v.Anchored = false
end
end
Wood:Destroy()
--Drop Wood
WG.BG.Visible = false
GetWood = true
end
end
end)

2 comments
if Char then
Since my fix worked, could you accept it?