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

Why doesn't GetPropertyChangedSignal() fire with this BoolValue?

I have this script in ServerScriptService that is supposed to check when a value in ReplicatedStorage changes, and fires a Bindable event.

local BeginGameEvent = workspace.BindableEvents.BeginGame
local GameStart = game:GetService("ReplicatedStorage").GameStart

GameStart.Value = true --changes the value

GameStart:GetPropertyChangedSignal("Value"):Connect(function() --checks for the change
	print(GameStart.Value)
	if GameStart.Value == true then
		print("starting game...")
		BeginGameEvent:Fire() --fires the bindable event for below
		GameStart.Value = false
	end
end)

BeginGameEvent.Event:Connect(function()
	local lighting = game:GetService("Lighting") --sets up lighting properties
	
	print("setting up lighting")
	
	lighting.TimeOfDay = 12
	lighting.FogEnd = 1000000	
end)

For some reason, the GetPropertyChangedSignal() never fires, since it never prints anything. No errors in the output either. However, the part where I change the GameStart value does work and sets the value from false to true. I also tried firing the BindableEvent manually in the command bar, but that didn't work either? I really don't understand what's going on, and this has really stumped me.

1 comment

0

If my answer has helped you then please mark it as the accepted answer.

2 answers

You are changing the value of GameStart before you have connected the Event.

Move GameStart.Value = true to just after the connection

local BeginGameEvent = workspace.BindableEvents.BeginGame
local GameStart = game:GetService("ReplicatedStorage").GameStart

GameStart:GetPropertyChangedSignal("Value"):Connect(function() --checks for the change
    print(GameStart.Value)
    if GameStart.Value == true then
        print("starting game...")
        BeginGameEvent:Fire() --fires the bindable event for below
        GameStart.Value = false
    end
end)

GameStart.Value = true --changes the value

BeginGameEvent.Event:Connect(function()
    local lighting = game:GetService("Lighting") --sets up lighting properties

    print("setting up lighting")

    lighting.TimeOfDay = 12
    lighting.FogEnd = 1000000   
end)

You can't use GetPropertyChangedSignal on values, you should be using Changed, for example:

local Bool = Instance.new('BoolValue');
Bool.Parent = game.ServerStorage;

Bool.Changed:Connect(function(Value) -- Value is the new value.
    print(Value);
end)

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