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

Use table from another script?

Asked by
baxzzi 42
5 years ago
Edited 5 years ago

I want to put my table in another separate place so I can grab it with all my other scripts that requires it. It would be much easier just to change only one script instead of many other ones.

local admins = {
    [43764376] = true;--baxzzi
    [123268417] = true;--canadian_kidgamer
    [86489853] = true;--JonathanParkourPro
}

This is the table I want to grab and use it as a "local variable" for other scripts to use. Anyone know how to achieve this?

Here's the whole the script that this table is in.

local players = game:GetService('Players')
local me = players:GetPlayerFromCharacter(script.Parent)
local character = me.Character
local head = character:WaitForChild("Head")

local nametag = game.ServerStorage:WaitForChild("nameTag")
local cloned = nametag:Clone()
local type1 = cloned:WaitForChild("type1")
local line1 = type1:WaitForChild("line1")
local imageFrame = type1:WaitForChild("imageFrame")
local rank = imageFrame:WaitForChild("rank")

local debug = game.ServerScriptService.debugMode.Value

local admins = {
    [43764376] = true;--baxzzi
    [123268417] = true;--canadian_kidgamer
    [86489853] = true;--JonathanParkourPro
}

cloned.Parent = head
cloned.Adornee = head
cloned.type1.Visible = true
line1.Text = "Player ".."(".. me.name ..")"
imageFrame.Visible = true

if admins[me.userId] then 
    imageFrame.Size = UDim2.new(0.35,0,0.3,0)
    imageFrame.Position = UDim2.new(0.32,0,0.3,0)
    imageFrame.ImageColor3 = Color3.fromRGB(255, 82, 85)
    rank.Text = "ADMIN"
else
    print('not admin')
end
0
oooh what type of script RetroGalacticGamer 331 — 5y
0
Why not use a module, and have the scripts require the module? TheeDeathCaster 2368 — 5y
0
I posted that, though It didn't seem to be effective. Ziffixture 6913 — 5y
0
tbh, modules would be better for this theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You could use remote events or bindable events. So basically, you make your table variable a tuple argument in your event, and then you send it. When the other script receives it(just in case you don't know, bindable events are for communicating server to server or client to client and remote events are for communicating client to server or server to client, but I will be doing bindable example), the argument (in this case your table) will be passed to the other script, and you can use it. Take your table, for example. I will send your table from a server script to a server script and the script that receives the table will print it's contents. Ready? So first, let's get the bindable event set up. This looks similar to your script, only I add the bindable event. Now you can send your table to another script.

wait(2)
local admins = {
    ["43764376"] = true;--baxzzi
    ["123268417"] = true;--canadian_kidgamer
    ["86489853"] = true;--JonathanParkourPro
}
    game.ReplicatedStorage.BindableEvent:Fire(admins)


There! almost done. So just to summarize what I did, I just took your table and made it a tuple argument inside your event. Now, to the other script!

game.ReplicatedStorage.BindableEvent.Event:Connect(function(admins)
    for Key, Value in pairs(admins) do
        print(Key)
        print(Value)
        wait(1)
    end
end)

So this will wait for the event to be fired, and it will find your table argument and set it to the parameter "admins". It will then iterate through your table until it prints every key and value. Feel free to do whatever you want with the table! You don't have to print it! If you are using client to server or server to client communication, be sure to use a remote event k. I hope this helps. :)

0
Be sure to upvote and accept if it helps! :) RetroGalacticGamer 331 — 5y
0
Looks like it works with my kind of format, however how would I be able to implent it into my script that I posted? Sorry if I seem too dumb or annoying. baxzzi 42 — 5y
0
yes, yes you would. just fire the event whenever you would like and make sure your table is BEFORE you fire it, please RetroGalacticGamer 331 — 5y
0
that way it doesn't get triggered as nil. As long as you do this, you can do anything you want with the table you have. RetroGalacticGamer 331 — 5y
View all comments (2 more)
0
thanks for accepting! RetroGalacticGamer 331 — 5y
0
Well, okay so I think you read my question wrong, I asked how would I be able to implent it into my script. But thanks for the help. :) baxzzi 42 — 5y
Ad

Answer this question