When trying use GetPropertyChangedSignal when the Value is Changed the function doesn’t run
local InRound = game.ReplicatedStorage.InRound
local IntermissionLabel = game:GetService("StarterGui").Intermission.IntermissionLabel
local Minigames = game.ReplicatedStorage.Minigames
InRound.Value = true
InRound.Value = false -- Making sure a round begins when the server is starting
local function ChooseMinigame()
local Children = Minigames:GetChildren()
local Index = math.random(#Children)
local ChosenName = Children[Index]
return ChosenName
end
InRound:GetPropertyChangedSignal("Value"):Connect(function()
print("e")
if InRound.Value == false then
print("Starting Round")
InRound.Value = true
local RandomMinigame = ChooseMinigame()
game.ReplicatedStorage.UpdateTextLabel:FireAllClients(RandomMinigame)
end
end)
I have verified with prints that the Value is changing and the function is not running when it changes.
I have also tried .Changed but that doesn’t work either.
1 Like
Well the problem is not GetPropertyChangedSignal as you stated it prints when the value changes, rather it’s the functions you’ve set up. Take an extra look at the function ChooseMinigame()
1 Like
I dont understand. Aren’t functions supposed to be placed at the top of the script most of the time?
1 Like
Well it’s really where you want to put the function. Functions are just used to make code cleaner and easier to read, so it’s a preferred option and where to place them is how your code is written out. Like say for the function I need a specific value I would place the function in that scope of the value.
1 Like
Also I’ve tried this code and it works perfectly fine for me. It randomizes the mini game and prints everything, so maybe it’s something else you wrote.
1 Like
That’s the entire code, and so far there are no other scripts in the game besides one that receives the event that is fired later in the script.
1 Like
print and show me the output.
remove print(“e”) and under (if InRound.Value == false then) print(“False”)
1 Like
Nothing shows up in the output.
1 Like
wait before did (“e”) show up?
1 Like
No, it did not show up. I tried removing the function but that didn’t change anything.
1 Like
Ok well I got it to work, here is my code:
Server
local InRound = game.ReplicatedStorage.InRound
local Minigames = game.ReplicatedStorage.Minigames
local function ChooseMinigame()
local Children = Minigames:GetChildren()
local Index = math.random(#Children)
local ChosenName = Children[Index]
return ChosenName.Name
end
InRound.Changed:Connect(function()
if InRound.Value == false then
local randomMinigame = ChooseMinigame()
game.ReplicatedStorage.UpdateLabel:FireAllClients(randomMinigame)
end
end)
Client
game.ReplicatedStorage.UpdateLabel.OnClientEvent:Connect(function(Chosen)
script.Parent.TextLabel.Text = Chosen
end)
That doesn’t work either, for some reason what always happens with my posts is that other people will try and say it worked for them but it doesn’t work for me. Is my Studio bugged or something?
Can you show the client script where you fired all clients to?
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.UpdateTextLabel.OnClientEvent:Connect(function(randomMinigame)
print(randomMinigame)
end)
local InRound = game.ReplicatedStorage.InRound --> InRound boolvalue TRUE
local IntermissionLabel = game:GetService("StarterGui").Intermission.IntermissionLabel
local Minigames = game.ReplicatedStorage.Minigames
local function ChooseMinigame()
local Children = Minigames:GetChildren()
local Index = math.random(#Children)
local ChosenName = Children[Index]
return ChosenName
end
InRound:GetPropertyChangedSignal("Value"):Connect(function()
print("e")
if InRound.Value == false then
print("Starting Round")
InRound.Value = true
local RandomMinigame = ChooseMinigame()
game.ReplicatedStorage.UpdateTextLabel:FireAllClients(RandomMinigame)
end
end)
task.wait(1)
InRound.Value = false --> At the end
Try this, I think its because you change the variable, before the function knows what changed… because its down
1 Like
I think it may be because you never actually change the value of InRound anywhere else.
Do This:
while true do
InRound.Value = true
wait(2)
InRound.Value = false
end
Obviously this won’t be permanent in your game but it will be a test for now
1 Like
Pyracolle reply fixed the issue, I appreciate you trying to help though! (Also you both suggested me to do basically the same thing at the end so thanks to both of you for fixing it I guess lol)
Yeah no problem! Glad you got it working though, also is this like a new game or something
I just got started in development, so I guess yes.
Nice. Mini games are a pretty good place to start.
1 Like