Update value help

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)
1 Like

does anyone need more information?

i’m not really sure what’s going on

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)

ok, to answer some of you questions, the character only has 1 axe at once, twx is a gamepass value also, your script does not add wood to the value.

because there wasn’t a wood value in your script

This is above the script

local wood =leaderstats.Wood

it does not add wood

wood.Value += Damage.Value * (twxWood.Value and 2 or 1) -- Multiply by 2 if twxWood, otherwise 1

then the damage must not exist because i renamed everything

do you have output open

yes, now it is saying index nil with ‘waiiforchild’ for twxwood and it is spelled correctly btw

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

it is working, but from my orignal post the damage does not change when the tool gets changed, I will send a video for refrecne

Might be a stupid question, but did you check if the Damage value is changed within the tool?

how would i do that


how nevermind, i checked in the explorer and yeah it did change

can you run play and send screenshot of explorer how it looks under character

Change Wait to Find. I assume if you have gamepass you have it and if dont you dont.

local twxWood = axes:FindFirstChild("twxWood", 5)

yes that is correct


Thats why it was returning nil cuz it timed out and didnt find the child

I removed thast section because it is a gamepass