NumberValue in ReplicatedStorage not changing from Server Script

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Change a NumberValue in ReplicatedStorage from a Server Script.

  2. What is the issue? When changing the value with the script below, The script prints the correct value, but when playtesting, as both the Client and Server, the value doesnt actually change. Im not sure how its getting the value that its printing if the value isnt changing.

local events = {
	"Speed",
	"Big Head",
	"Slow"
}

local rs = game:GetService("ReplicatedStorage")

local cooldown = rs:WaitForChild("Cooldown").Value

while true do
	if cooldown == 0 then
		local random = math.random(1, #events)
		local event = events[random]
		
		game.ReplicatedStorage.Event.Value = event
		
		if event == "Speed" then
			print("Speed")
		elseif event == "Big Head" then
			print("Big Head")
		elseif event == "Slow" then
			print("Slow")
		end
		
		cooldown = 10
		print(cooldown)
	elseif cooldown <= 10 then
		wait(1)
		cooldown -= 1
		print(cooldown)
	end
end

(Edit: I tried using an IntValue too, which did not change anything. The Event value mentioned in the script above does change. But the cooldown value does not.)

When you’re changing the cooldown variable, all you’re doing is updating the variable’s value. This is because you’re assigning the variable the value of the “Cooldown” instance. To fix this, just drop the “.Value” part and update the spots where you want to change the value.

local cooldown = rs:WaitForChild("Cooldown")

cooldown.Value -= 1
3 Likes

Thank you! I had just assumed using .Value in the variable would be the same as putting it in the spots where the values are being changed.

1 Like

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