Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can you check if a player is in a table from another script?

Asked by
MattVSNNL 620 Moderation Voter
3 years ago

So I'm making a feature not specifying what feature, But in the MainScript I have a table with every player, So in another script I want to give every player in the table more speed, But I can't figure out how, I tried many things, May anyone help me?

0
You can use bindable events or remote event/functions JesseSong 3916 — 3y

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

I think you are going to need to post more context, but here is my answer from I can obtain.

Assuming both scripts are server sided:

local event = game.ReplicatedStorage.BindableEvent  -- some event you have

event.Event:Connect(function(players)
    for i, player in pairs(players)  do
        local char = player.Character or player.CharacterAdded:Wait()

        char.Humanoid.WalkSpeed += 10 -- increases speed
    end
end)


-- in the main script

local event = game.ReplicatedStorage.BindableEvent

local players = {} -- your table

event:Fire(players) -- this is how you fire the server, call this whenever you need to increase the speed
0
Thanks MattVSNNL 620 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

The most efficient option is to use ModuleScripts, as you can then access tables directly (if you put the table in what is returned by the Module), example:

Module Script:

local module = {}
local someTable = {}
module.SomeTable = someTable
-- can use someTable here
return module

Script:

local Module = require(path.to.module.script.here)
-- You can now use Module.SomeTable here
0
Sorry, I already accepted someone elses answer MattVSNNL 620 — 3y
0
But thanks for trying to help MattVSNNL 620 — 3y

Answer this question