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

How to make scripts read other scripts?

Asked by 10 years ago
        local sheriff   
        local murderer
        local innocent  = {}

        local players = game.Players:GetPlayers()
        murderer = players[math.random(#players)].Name
        sheriff = players[math.random(#players)].Name
        for i,v in pairs(players) do 
            if v.Name ~= sheriff and v.Name ~= murderer then 
                table.insert(innocent, v.Name)
            end
        end

        print("MURDERER: "..murderer,"SHERIFF: "..sheriff, "INNOCENTS: "..table.concat(innocent,", "))

Ok, so I have tried the wiki, for about 4 hours, with no luck. This script will pick 1 murder, 1 sheriff, and the rest innocent, but I need another script within a gui needs to read this and check what role a player has, so it tells the players what role they have. Anyone have a solution

3 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
10 years ago

Roblox Roblox locked the source property of scripts, my best solution I could give is using the _G. Tag to make the innocent table and murder/sheriff tags a global value to be used throughout the game.

0
so how would the other script check the players role? NinjoOnline 1146 — 10y
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

The script would receive all global variables. If you want a Global function, go here. If you just want a variable? Go here.

So, in your case, you'd put _G.Players or _G.murderer.

Also, remove line 1 and 2.

~ Thank me by accepting this answer.

0
So _G.murder in its variable, then in the other script I type if player = murderer then?? NinjoOnline 1146 — 10y
0
In the other script, you'd type `if _G.player.Name == _G.murder.Name then` Shawnyg 4330 — 10y
0
But so where does the _G. go in the script above? NinjoOnline 1146 — 10y
0
Just use _G. for any variable you have that you want to access in the script. So, right now, I can probably tell you want players, murderer, and Sheriff. So, put _G. before every variable (no space). Shawnyg 4330 — 10y
Log in to vote
0
Answered by
Ekkoh 635 Moderation Voter
10 years ago

Or use the solution I told you in the other post you made. No double posts please.

Answer this question