Im trying to understand how parameters work? Do they work like you send a value through them and then when you call it you can get the value?
local function updatedamg(idk) -- value want to be sent
local Character = plr.Character or plr.CharacterAdded:Wait()
local Axe = SearchForAxe(Character)
local idk = Axe:FindFirstChild("damage").Value
print(idk.Value)
end
AddWoodEvent.OnServerEvent:Connect(function(Player) -- (A) Were you supposed to add "Wood" as a parameter
local DamageValue = 0
updatedamg(DamageValue) --value added to othervalue?
if not DamageValue 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:FindFirstChild("twxWood", 5)
print(DamageValue)
wood.Value += DamageValue * (twxWood.Value and 2 or 1) -- Multiply by 2 if twxWood, otherwise 1
DamageValue = 0
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Ok so when i impliment this into my code it should work like this right? But it is warning “axe has no damage value”?
local function updatedamg(idk)
local Character = plr.Character or plr.CharacterAdded:Wait()
local Axe = SearchForAxe(Character)
local idk = Axe:FindFirstChild("damage").Value --finding the value
print(idk)
end
AddWoodEvent.OnServerEvent:Connect(function(Player) -- (A) Were you supposed to add "Wood" as a parameter
DamageValue = updatedamg(DamageValue) --add dmg
if not DamageValue 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:FindFirstChild("twxWood", 5)
print(DamageValue)
wood.Value += DamageValue * (twxWood.Value and 2 or 1) -- Multiply by 2 if twxWood, otherwise 1
DamageValue = 0
end)
Ok, i understand more now, but i think im setiting “damage value” to idk’s value. But damage value is printing nil?
local function updatedamg(idk: NumberValue)
local Character = plr.Character or plr.CharacterAdded:Wait()
local Axe = SearchForAxe(Character)
local idk = Axe:FindFirstChild("damage").Value --getting idks value
print(idk)
end
AddWoodEvent.OnServerEvent:Connect(function(Player)
DamageValue = updatedamg(DamageValue) --setting the damage value to idks value
print(DamageValue)
if not DamageValue 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:FindFirstChild("twxWood", 5)
print(DamageValue)
wood.Value += DamageValue * (twxWood.Value and 2 or 1)
DamageValue = 0
end)
You have made what is called a procedure, it does not return a value. This means DamageValue comes out as nil, which means the asbence of data (e.g. nothing). You must add a return statement returning the value you want DamageValue to take.
local DamageValue = 0 --setting damage vllue
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
local function updatedamg(idk: NumberValue)
local Character = plr.Character or plr.CharacterAdded:Wait()
local Axe = SearchForAxe(Character)
local idk = Axe:FindFirstChild("damage").Value
print(idk)
end
AddWoodEvent.OnServerEvent:Connect(function(Player)
DamageValue = updatedamg(DamageValue)
print(DamageValue)
if not DamageValue 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:FindFirstChild("twxWood", 5)
print(DamageValue)
wood.Value += DamageValue * (twxWood.Value and 2 or 1)
DamageValue = 0
end)
Simple: You just add a return statement to return the value you want. Here’s a brief example using addition:
local function add(n1, n2)
local result = n1 + n2
return result --send it back to whatever requested it
end
local sum = add(5, 7) --get the return result of the function and store it in "sum"
print(sum) --outputs "12"