Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not detecting value change?

I was trying to make a sliding door that opens when ServerStorage.ElevatorValues.Easy.Intermission.Value == 60 but for some reason my script doesn't detect the value in the serverstorage? (I've Tested the door and it works fine, Changing the serverstorage value also works fine, This script is a server script in a part which is in the workspace) The script doesn't print("test") or test2. Here is the script:

wait()
local ServerStorage = game:WaitForChild("ServerStorage")
local ElevatorValues = game:WaitForChild("ElevatorValues")
local Easy = game:WaitForChild("Easy")
local Intermission = game:WaitForChild("Intermission")
while wait() do
		if ServerStorage.ElevatorValues.Easy.Intermission.Value == 60 then
			print("test")
			for i = 1, 100 do
			wait()
			script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, 0.1, 0)
		end
	end
	if ServerStorage.ElevatorValues.Easy.Intermission.Value == 10 then
		print("test2")
	for i = 1, 100 do
		wait()
		script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0, -0.1, 0)
	end
	wait(3)
	end
end

If you know why this is happening please let me know!

1 comment

0

Your local ElevatorValues WaitForChild is looking for a directory called ElevatorValues, I assume its supposed to be Local ElevatorValues = ServerStorage:WaitForChild("ElevatorValues") right? Anyway, the script won't run because it's waiting for that child

1 answer

✓ Accepted answer

Never use loops when you have events available. All ValueObjects have a Changed event that run when the value held is changed andit also passes the new value.

Example:-

local valueObj = game:WaitForChild("ServerStorage").ElevatorValues.Easy.Intermission
local part = script.Parent

valueObj.Changed:Connect(function(newVal) 
	if newVal == 60 then
		for i=1, 100 do
			part.CFrame = part.CFrame * CFrame.new(0, 0.1, 0)
			wait()
		end
	elseif newVal == 10 then
		for i=1, 100 do
			part.CFrame = part.CFrame * CFrame.new(0, -0.1, 0)
			wait()	
		end
	end
	print("ran", newVal) -- debug code
end)

This is just a quick example and there are far better way to make this code. Add some more prints to find out why your code is not running as expected.

Hope this helps

This discussion is preserved as it was. New answers, comments, and votes are closed.