Changing value not working?

i have a leader stat in the server script strage which creates the values, heres the server script

local PlayerS = game:GetService("Players")

PlayerS.PlayerAdded:Connect(function(player)
	local Resources = Instance.new("Folder",player)
	Resources.Name = "Resources"
	local Wood = Instance.new("NumberValue",Resources)
	Wood.Value = 10
	Wood.Name = "Wood"
	local Rock = Instance.new("NumberValue",Resources)
	Rock.Value = 5
	Rock.Name = "Rock"
	local Metal = Instance.new("NumberValue",Resources)
	Metal.Value = 10
	Metal.Name = "Metal"
end)

and here is the changing event

local RS = game:GetService('ReplicatedStorage')
local Event = RS:WaitForChild('Metal')

-- PlaceBlock Event

Event.OnServerEvent:Connect(function(plr)
	plr.Resources.Metal.Value = plr.Resources.Metal.Value - 1
end)

and here is the event sender

script.Parent.Activated:Connect(function()
	if value ~= 1 then
		local target = mouse.Target
		if target then
			local surface = mouse.TargetSurface
			local pos = Surface(surface)
			Event:FireServer(target,pos,Block_Choice)
			value = value - 1
		end
		if value == 1 then
			if target then
				local surface = mouse.TargetSurface
				local pos = Surface(surface)
				Event:FireServer(target,pos,Block_Choice)
				Me:FireServer()
				equipped = false
				part.Transparency = 1
				part.Position = Vector3.new(1,1,1)
				script.Parent:Destroy()
			end
		end
	end

Any Errors? on your console output

One thing I can see wrong with the last script is that there is a block of code that will never have the chance to run. What I’m talking about is the “if value == 1 then”. This will never run because it’s inside “if value ~= 1 then”

Try this.

script.Parent.Activated:Connect(function()
	local target = mouse.Target
	if value ~= 1 then
		if target then
			local surface = mouse.TargetSurface
			local pos = Surface(surface)
			Event:FireServer(target,pos,Block_Choice)
			value = value - 1
		end
	elseif value == 1 then
		if target then
			local surface = mouse.TargetSurface
			local pos = Surface(surface)
			Event:FireServer(target,pos,Block_Choice)
			Me:FireServer()
			equipped = false
			part.Transparency = 1
			part.Position = Vector3.new(1,1,1)
			script.Parent:Destroy()
		end
	end
1 Like

no errors on the output for some reason

hmm nope still not changing the value

Where is the script placed? In serverscriptservice?

this one is located in a tool as a local scipt, its not the full script tho, its the part that i think is the problem