So whenever the player clickes with a tool it sends a remote event. The remote events checks for the damge of the tool. Whenever there is a new tool that the player clicks it checks for the same damage and for somereason it stays the same as the first one and does not change to the second tools damage?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local addWoodRemoteEvent = ReplicatedStorage.AddWood
addWoodRemoteEvent.OnServerEvent:Connect(function(player)
local Character = player.Character or player.CharacterAdded:Wait()
local axe
local function lookForAxe(container)
for _, item in container:GetChildren() do
if axe ~= nil then break end
if item:IsA("Tool") and item.Name == "Axe" then
axe = item
end
end
end
lookForAxe(Character)
if axe ~= nil then
local damage = Character:WaitForChild("Axe"):WaitForChild("damage", 5)
local axes = plr:WaitForChild("axes", 5)
local twxWood = axes:WaitForChild("twxWood", 5)
if not damage then return end
if not axes then return end
if not twxWood then return end
print(damage.Value)
if twxWood.Value == true then
wood.Value += damage.Value * 2
else
wood.Value += damage.Value
end
end
end)
local RS = game:GetService("ReplicatedStorage")
local AddWoodEvent = RS.AddWood
local function SearchForAxe(Container) -- Move local function outside of connection
for _, Item in Container:GetChildren() do
if not Item:IsA("Tool") or Item.Name ~= "Axe" then continue end
return Item
end
end
AddWoodEvent.OnServerEvent:Connect(function(Player) -- (A) Were you supposed to add "Wood" as a parameter
local Character = Player.Character or Player.CharacterAdded:Wait()
local Axe = SearchForAxe(Character) -- (B) Does the character have multiple axes at once?
if not Axe then return end -- Player has no axe equipped
local Damage = Axe:WaitForChild("Damage", 5) -- (B) Use the axe you just searched for
local PlayerAxes = Player:WaitForChild("Axes", 5) -- Why do you need all axes? (Damage comes from 1 axe)
local twxWood = PlayerAxes:WaitForChild("twxWood", 5) -- What is 'twx'
if not Damage then return end
if not PlayerAxes then return end
if not twxWood then return end
print(Damage.Value)
Wood.Value += Damage.Value * (twxWood.Value and 2 or 1) -- Multiply by 2 if twxWood, otherwise 1
-- (A) Unknown 'Wood'
end)
when you say âfor twxWoodâ iâm assuming you mean the line
local twxWood = axes:WaitForChild("twxWood", 5)
Attemped to Index nil with 'WaitForChild' would mean Axes is nil
and i just realized your returns arenât in the right spots
local Damage = Axe:WaitForChild("Damage", 5)
if not Damage then warn("Axe has no damage value") return end
local PlayerAxes = Player:WaitForChild("Axes", 5)
if not PlayerAxes then warn("Player has no axes") return end
local twxWood = PlayerAxes:WaitForChild("twxWood", 5)
if not twxWood then warn("Player has no twxWood") return end