Can't send values to server scripts

Hi
I’m trying to send some numbervalues inside my table through my localscript to my serverscript.
The problem is the button code.

Localscript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local materialGenerationRate = 40
local tutorialDone = false
local toggled = false
local lootTaken = false
local adv = game.Workspace:WaitForChild("AdventurerClick")
local stage1 = adv:WaitForChild("Stage1")

local wood = stage1:WaitForChild("Wood")
local arrow = stage1:WaitForChild("Arrow")
local commonHerbs = stage1:WaitForChild("Common herbs")
local madnessChunk = stage1:WaitForChild("Madness chunk")
local nanoHealingPotion = stage1:WaitForChild("Nano healing potion")

local clicked = false

local function generateMaterials()
	if not stage1 then return end
	
	wood = wood + 2
	arrow = arrow + 5
	commonHerbs = commonHerbs + 1
	madnessChunk = madnessChunk + 1
	nanoHealingPotion = nanoHealingPotion + 1
end


local function startMaterialGeneration()
	while tutorialDone do
		if game.Lighting.ClockTime > 8 and game.Lighting.ClockTime < 20 then
			if toggled then
				toggled = false
				game.Workspace.NPCs["The Adventurer"].Parent = ReplicatedStorage.npcOut
			end
			generateMaterials()
			wait(materialGenerationRate)		
		elseif not toggled then
			toggled = true
			ReplicatedStorage.npcOut["The Adventurer"].Parent = game.Workspace.NPCs
		end
	end
end

adv.ClickDetector.MouseClick:Connect(function(player)
	if not toggled then
		if not clicked then
			clicked = true
			
			if not tutorialDone then
				if not lootTaken then
					lootTaken = true
					wood = 120
					arrow = 250
					commonHerbs = 20
					madnessChunk = 20
					nanoHealingPotion = 20
				end
			end
			
			local materialsToSend= {}

			for _,mat in ipairs(stage1:GetChildren()) do
				if mat:IsA("NumberValue") then
				table.insert(materialsToSend,mat.Value)
				end
			end

			ReplicatedStorage.Events.AdventurerClaim:FireServer(materialsToSend)
			
			print(materialsToSend)
			
			wait(1)
			
			wood = 0
			arrow = 0
			commonHerbs = 0
			madnessChunk = 0
			nanoHealingPotion = 0
			print("Done resetting")
			
			clicked = false
		end
	end
end)

Serverscript:

local tutorialDone = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local noiseMade = false
local claimNoise = game.StarterGui:WaitForChild("AdventurerClaimNoises")
local noiseTab = claimNoise:GetChildren()


ReplicatedStorage.Events.AdventurerClaim.OnServerEvent:Connect(function(player, tab)
	for i,v in ipairs(tab) do
		local materialsFolder = player:FindFirstChild("Materials")
		if materialsFolder then
			if i == 1 then
				materialsFolder["Wood"].Value = materialsFolder["Wood"].Value + v
				if v > 0 and not noiseMade then
					noiseMade = true
					local randomNoise = noiseTab[math.random(1,#noiseTab)]
					randomNoise:Play()
				end	
			elseif i == 2 then
				materialsFolder["Arrow"].Value = materialsFolder["Arrow"].Value + v
				if v > 0 and not noiseMade then
					noiseMade = true
					local randomNoise = noiseTab[math.random(1,#noiseTab)]
					randomNoise:Play()
				end
			elseif i == 3 then
				materialsFolder["Common herbs"].Value = materialsFolder["Common herbs"].Value + v
				if v > 0 and not noiseMade then
					noiseMade = true
					local randomNoise = noiseTab[math.random(1,#noiseTab)]
					randomNoise:Play()
				end
			elseif i == 4 then
				materialsFolder["Madness chunk"].Value = materialsFolder["Madness chunk"].Value + v
				if v > 0 and not noiseMade then
					noiseMade = true
					local randomNoise = noiseTab[math.random(1,#noiseTab)]
					randomNoise:Play()
				end
			elseif i == 5 then
				materialsFolder["Nano healing potion"].Value = materialsFolder["Nano healing potion"].Value + v
				if v > 0 and not noiseMade then
					noiseMade = true
					local randomNoise = noiseTab[math.random(1,#noiseTab)]
					randomNoise:Play()
				end
			end
			noiseMade = false
		end
	end
end)

I know the problem, I just don’t know how to fix it.
It’s this line that won’t change the values:

if not tutorialDone then
				if not lootTaken then
					lootTaken = true
					wood = 120
					arrow = 250
					commonHerbs = 20
					madnessChunk = 20
					nanoHealingPotion = 20
				end
			end

Thanks for any help!

2 Likes

I fixed it. I just forgot to add “Value” after my variable.
So, this line: wood = 120
Should’ve been: wood.Value = 120

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.