(This is filtering enabled)
The title is vague, but let me explain:
I want this code to run when a value in the replicatedStorage has changed:
game.Players.PlayerAdded:connect(function(plr) if game.ReplicatedStorage.keepTrackOfVariablesPlease.Value == true then wait() for i = 0, #game.Players:GetChildren(), 1 do x = i end --counting warn("Counting") if x >= 1 then print(x) game.ReplicatedStorage.ValidPlayerCounter:Fire() warn("Game can start now!") game.ReplicatedStorage.validPlayerCount.Value = true game.ReplicatedStorage.canStart.Value = true else print(x) game.ReplicatedStorage.nonValidPlayerCount:Fire() game.ReplicatedStorage.validPlayerCount.Value = false end game.ReplicatedStorage.gameStarted.Changed:connect(function() if game.ReplicatedStorage.keepTrackOfVariablesPlease.Value == true then if game.ReplicatedStorage.canStart.Value == true then local chosen = math.random(1, table.getn(spawners)) local picked = spawners[chosen] plr.Character.UpperTorso.CFrame = CFrame.new(workspace.Teleports:FindFirstChild(picked).Position + Vector3.new(0,3,0)) game.ReplicatedStorage.stopOn.Value = true for i,v in pairs(game.Players:GetChildren()) do if v:FindFirstChildWhichIsA("Player") then local thread = Instance.new("BoolValue") thread.Parent = game.Players.Alive thread.Name = plr.Name end end end end end) end end)
The thing is; that the only way I can get this to work is to put it in the "onPlayerAdded" function, which makes it only run once. I want this to run multiple times, so I was wondering what function I'd put it in and how to get that value of the player?
To get your code to run every time a value changes in ReplicatedStorage, you can simply just connect the value’s changed event to a function like this:
local value = game:GetService(“ReplicatedStorage”):FindFirstChild(“ValueName”) value.Changed:Connect(function() print(“Your code here”) end)
It’s a simple way.