So i want this script to make it so when you equip a different axe it remvoes the other one and checks to see if the other one is in the backpack or the players hand and remove it and replace it with the other one that they chose, but i dont know what this error is saying?
local rp = game:GetService("ReplicatedStorage")
local axe = rp.Axes.Diamondaxe.Axe
local plr = game:GetService("Players")
local player = plr.LocalPlayer
local function checktool()
for _, child in pairs(player.Character:GetChildren()) do
if child:IsA("Tool") then
child:Destroy()
local newaxe = axe:Clone()
newaxe.Parent = player.Backpack
end
end
return nil
end
local function checktool2()
for _, child in pairs(player.Backpack:GetChildren()) do
if child:IsA("Tool") then
child:Destroy()
local newaxe = axe:Clone()
newaxe.Parent = player.Backpack
end
end
return nil
end
script.Parent.MouseButton1Click:Connect(function()
checktool()
checktool2()
end)
18:26:43.635 Players.TheReal_MrMonkey.Backpack.Axe.Handle.Script:11: attempt to index nil with ‘Parent’ - Studio
18:26:43.635 Stack Begin - Studio
18:26:43.635 Script ‘Players.TheReal_MrMonkey.Backpack.Axe.Handle.Script’, Line 11 -
Going off of the logical explanation based on the error here, the variable newaxe is nil. Lua is complaining that you are trying to index the nil value inside your newaxe variable with .Parent.
no it is not, ill send the srcipt that is having the problems
local rp = game:GetService("ReplicatedStorage")
local axe = rp:WaitForChild("Axes"):WaitForChild("Diamondaxe"):WaitForChild("Axe")
local plr = game:GetService("Players")
local player = plr.LocalPlayer
local function checktool()
for _, child in pairs(player.Character:GetChildren()) do
if child:IsA("Tool") then
child:Destroy()
print(axe)
local newaxe = axe:Clone()
newaxe.Parent = player.Backpack
end
end
end
local function checktool2()
for _, child in pairs(player.Backpack:GetChildren()) do
if child:IsA("Tool") then
child:Destroy()
local newaxe = axe:Clone()
newaxe.Parent = player.Backpack
end
end
end
script.Parent.MouseButton1Click:Connect(function()
checktool()
checktool2()
end)
local handle = script.Parent
local Players = game:GetService("Players")
local goi = Players.LocalPlayer.PlayerGui.Gui
local Tween = game:GetService("TweenService")
local Replicatedstorage = game:GetService("ReplicatedStorage")
local Woodadd = Replicatedstorage.Wood
local woodPosition = UDim2.new(0.253, 0,-0.028, 0)
local tweenInfo = TweenInfo.new(2)
local leaderstats = Players.LocalPlayer:WaitForChild("leaderstats")
local wood = leaderstats.Wood
local damage = script.Parent.Parent.damage
local canSwing = true
db = true
dbbb = true
for i, v in pairs(handle.Parent:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
v.Touched:Connect(function(hit)
if hit.Parent.Name == "Tree"and db == true and not canSwing and hit.Parent.Canbeattacked.Value == false then
local amount
if goi:FindFirstChildOfClass("IntValue") then -- since you parent your int value to the goi thing I checked that
else
amount = Instance.new("IntValue")
amount.Parent = goi
end
amount = goi:FindFirstChildOfClass("IntValue")
local tree = hit.Parent
local modelCFrame = tree:GetPivot()
local health = tree.Health
local DamageDelt = tree.DamageDelt
db = false
local oldpos = tree.Tree.CFrame.Position
local goal = {CFrame = script.Parent.CFrame * (CFrame.new(1,1,1) * CFrame.Angles(math.rad(75),0,0))}
local tweenlog = Tween:Create(tree.Tree,tweenInfo,goal)
goi.CanvasGroup.Visible = true
health.Value -= damage.Value
DamageDelt.Value += damage.Value
amount.Value += 1
local function wodas()
goi.CanvasGroup.Amount.Size = UDim2.new(DamageDelt.Value/100,0,0,75)
local random = math.random(1,90)
local xnew = random/100
local wood2 = game.ReplicatedStorage.Wood:Clone()
wood2.Parent = Players.LocalPlayer.PlayerGui.Items
wood2.Position = UDim2.new(xnew,0,0.76,0)
wood2.TextLabel.Text = "+"..damage.Value
local tween = Tween:Create(wood2, tweenInfo, {Position = woodPosition})
tween:Play()
wait(1.3)
wood2:Destroy()
end
if health.Value == 0 or health.Value < 0 then
print(health.Value)
wodas()
tweenlog:Play()
goi.CanvasGroup.Visible = false
goi.CanvasGroup.Amount.Size = UDim2.new(0.2,0,0,75)
amount:Destroy()
game.ReplicatedStorage.AddWood:FireServer()
hit.Parent.Canbeattacked.Value = false
dbbb = false
task.wait(20)
tree.Tree.CFrame = CFrame.new(oldpos)
dbbb = true
hit.Parent.Canbeattacked.Value = true
return
end
if health.Value <= 100 and dbbb == true then
goi.CanvasGroup.Amount.Size = UDim2.new(DamageDelt.Value/100,0,0,75)
wodas()
game.ReplicatedStorage.AddWood:FireServer()
end
task.wait(1)
db = true
else
print(hit.Parent.Name)
end
end)
end
end
handle.Parent.Activated:Connect(function()
if canSwing then
canSwing = false
task.wait(1)
canSwing = true
end
end)