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

Client not detecting an object has been added into a module script?

I'm using a module script as a table to access from anywhere, and this script adds a player into the module:

local participants = require(game.Workspace.Race.Participants)
game.ReplicatedStorage.Race.Race.OnServerEvent:Connect(function(player)
	table.insert(participants,#participants+1,player)
	print("ok "..#participants)
end)

And it prints "ok 1". Now for the local script:

local participants = require(game.Workspace.Race.Participants)
local CountDown = 10
print("ok")
while wait(1) do
	print("running")
	print(#participants)
	if #participants == 1 then
		print("Active")
		script.Parent.Text = CountDown
		CountDown = CountDown - 1
	end
end

It will print "ok" and "running", but after I insert the player into the table, the line "print(#participants)" will print 0, even tough it should print 1.

4 comments

0

Why don`t you use IntValues? Modules don't work like that, they only make the variable 'global' if it is set inside the module

0

I need the modules to store the participant's of the race, how will I store them in int's lol

0

Create Int/String/Object Values or any other, and then use a for loop to get the players

0

Ok I will try it

1 answer

When storing objects for later use it is always nice to use tables as it isn't creating tons of objects. You have a very great reason for using tables. You just don't know how.

I recommend using RemoteFunctions. Whenever the client needs to get all the participants it will run RemoteFunction:InvokeServer(). Once this is ran on the server you would have a function something like this:

RemoteFunction.OnServerInvoke = function()
	return participants
end

Of course it will require variable editing and positioning to fit your needs. This is probably the best way to do it, I hope it helps!

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