I need help on trying to write a line of code to notice when the NumberValue has changed.
Here is my line of script:
local tensemusic = script.Parent.tensemusic
local Spotted = script.Parent.Spotted
local LightLevel = workspace.LightLevel
local StopRising = Rising:Stop()
while true do
wait(math.random(20,30))
if LightLevel.Value == 1 then – checks if your light is on. If it’s 1, it is on. If it isn’t, it’s off and the monster does not see you.
Spotted:Play()
tensemusic:Play()
–Insert Something here to detect if Value doesn’t equal 1 anymore and then stops tensemusic from playing.
else
Spotted:Play()
end
end
I looked at topics related to my problem but none of them really helped me. I tried using Value.Changed, GetPropertyChangedSignal, and other stuff. I don’t know what I am doing wrong.
I only know how to do basic scripting so I need help on this. I’m also pretty new to creating topics so I’m sorry if I haven’t given you enough information.
You can use the “Changed” event which is shared by the various instance value types, like in the following. It fires whenever the value stored inside the value instance changes.
local tensemusic = script.Parent.tensemusic
local Spotted = script.Parent.Spotted
local LightLevel = workspace.LightLevel
local StopRising = Rising:Stop() --rising isnt defined here by the way
LightLevel.Changed:Connect(function(value)
if value == 1 then
Spotted:Play()
tensemusic:Play()
else
Spotted:Play()
end
end)
I’ve added a comment to one of the lines which might need your attention.
Oh! Ignore that. I forgot to take it out. That was a failed attempt of trying to make a solution to the problem. It was basically tense music but I changed “rising” to “tensemusic” so it made more sense.
I’m still a bit confused. The randomizer I have was the amount of seconds before the monster shows up. Is there a way I could implant that in the script?
So basically, if the value is one, the monster will spot you when it shows up. And if you turn off your light, the lightlevel value goes to 0, which then i need the “changed” line of script to make the tensemusic to stop. If the light is off before the monster arrives, the monster wont see you and the tense music wont play.
(the way you turn off the light is a click detector by the way)