Changed And GetPropertyChangedSignal dosent work

the code

CanSpectate.Changed:Connect(function(Value)
	if Value == true then
		print("visible")
		script.Parent.Visible = true
	else
		if Value == false then
			print("not visible")
			script.Parent.Visible = false
		end
	end
end)

i also tried

CanSpectate:GetPropertyChangedSignal("Value"):Connect(function()
	if CanSpectate.Value == true then
		print("visible")
		script.Parent.Visible = true
	else
		if CanSpectate.Value == false then
			print("not visible")
			script.Parent.Visible = false
		end
	end
end)
type or paste code here

both of them dosent work . i changed the value from serverside script

is there any errors in the output?

unfortunately No. the button visible shall be false if canspectate value is false

Is the code above from a local script or a server script?

Is the code that CHANGES the value from a local script or a server script?

You can do this:

CanSpectate.Changed:Connect(function(value)
   print(value)
   script.Parent.Visible = value
end)

the code that i gave is a “localscript” i changed the CanSpectate.Value from ServerScript

alr ill give it a try i did some debugging with prints() but it seems to not worked

Can you please put a print statement before and after the .Changed function

i.e.

print("BEFORE")
CanSpectate:GetPropertyChangedSignal("Value"):Connect(function()
	if CanSpectate.Value == true then
		print("visible")
		script.Parent.Visible = true
	else
		if CanSpectate.Value == false then
			print("not visible")
			script.Parent.Visible = false
		end
	end
end)
print("AFTER")

update: it only prints if i reset or die

alright it printed out Before And Visible

probably because you put this in a different script

Humanoid.Died:Connect(function()
   path.to.CanSpectate.Value = false
end)
1 Like

ye i wrote that code in my other scripts and i deleted it but its still dosent work

can you please send your entire script?

the serverscript one or the localscript one?

the one that contains the code that is not functioning correctly

here is the localscript (full)

local ReplicatedStorage  = game:GetService("ReplicatedStorage")
local Promise = require(ReplicatedStorage:WaitForChild("Modules"):FindFirstChild("Promise"))
local CanSpectate = ReplicatedStorage:WaitForChild("Values"):FindFirstChild("CanSpectate")
local button = script.Parent
local spectateframe = button.spectate_frame
local playername = button.spectate_frame:FindFirstChild("player_name")
local openNow = true

local position = 1

local player_list = {}

local currentCamera = workspace.CurrentCamera


CanSpectate:GetPropertyChangedSignal("Value"):Connect(function()
	if CanSpectate.Value == true then
		print("visible")
		script.Parent.Visible = true
	else
		if CanSpectate.Value == false then
			print("not visible")
			script.Parent.Visible = false
		end
	end
end)


local function updatePlayerList(exemptPlayer)
	Promise.new(function(resolve,reject)
		for i,v in pairs(game:GetService("Players"):GetPlayers()) do
			if v ~= exemptPlayer and not table.find(player_list,v) then
				table.insert(player_list,v)
			end
		end
	end):catch(warn)
	
	
end

local function updateCamera(playerSubject)
	Promise.new(function(resolve,reject)
		playername.Text = tostring(playerSubject)
		currentCamera.CameraSubject = playerSubject.Character
	end):catch(warn)
end


updatePlayerList()
game:GetService("Players").PlayerAdded:Connect(function()
	updatePlayerList()
end)

game:GetService("Players").PlayerRemoving:Connect(function(plr)
	updatePlayerList(plr)
end)




button.MouseButton1Up:Connect(function()
	if openNow == true then
		openNow = false
		spectateframe.Visible = true
		position = 1
		updateCamera(player_list[1])
	else
		openNow = true
		spectateframe.Visible = false
		updateCamera(game:GetService("Players").LocalPlayer)
	end
end)


button.spectate_frame.left.MouseButton1Up:Connect(function()
	position = position -1
	if position <1 then
		position = #player_list
	end
	
	updateCamera(player_list[position])
	
end)


button.spectate_frame.right.MouseButton1Up:Connect(function()
	position = position +1
	if position > #player_list then
		position = 1
	end
	updateCamera(player_list[position])
end)