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

How to get the player through a regular script but on a value change?

(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?

1 answer

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.

2 comments

0

Sorry, I guess I was a little too vague. I need it to teleport the person when this happens, but since this game is FE, I have to do it through a script, yet I don't know how I can get the player's character.

0

Nevermind, I found out how to do it.

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