Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

With this script I get an error that is very confusing....?

With this script I get an error that is very confusing....? Error: Players.Charnub.PlayerGui.ChopScript:19: attempt to index upvalue 'Char' (a nil value)

local Player = game.Players.LocalPlayer
local Char = Player.Character
local Mouse = Player:GetMouse()

local GetWood = true

function ShowProgress(Tree)
	if Tree == "Tree" then
		for i = 0,1,.01 do
			WC.MainFrame.LoadFake.LoadBar.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.Torso.Position).magnitude < 10 then
			GetWood = false
			WC = Player.PlayerGui.ChopGui
			WC.MainFrame.Visible = true
			Char.Humanoid.WalkSpeed = 0
			ShowProgress("Tree")
			Char.Humanoid.WalkSpeed = 16
			for i,v in pairs(Wood.Parent.Leaves:GetChildren()) do
				if v:IsA("UnionOperation")then
					v.Anchored = false
				end
			end
			Wood:Destroy()
			WC.MainFrame.Visible = false
			Player.leaderstats.Wood.Value = Player.leaderstats.Wood.Value + 3
			GetWood = true
		end
	end
end)

1 answer

✓ Accepted answer

So basically you are declaring 'Char' before it intializes, so do this:

local Char = Player.CharacterAdded:wait()

That basically waits until the character initializes before continuing.

This discussion is preserved as it was. New answers, comments, and votes are closed.