Ad
Log in to vote
1

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

Asked by
MattVSNNL 614 Moderation Voter
1 year 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 — 1y

2 answers

Log in to vote
1
Answered by 1 year ago
Edited 1 year 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 614 — 1y
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year 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 614 — 1y
0
But thanks for trying to help MattVSNNL 614 — 1y

Answer this question