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

Help with Variables in multiple scripts?

Asked by 8 years ago

I have got a script which gets the name of the person who touched that part, however, I need that name in a different script. How can I do this? Thanks

2 answers

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
8 years ago

If you mean by sharing variables with other scripts use the Global function or _.G, example.


-- script one.
_G.string="string"

-- script two.
print(_G.string)
Ad
Log in to vote
0
Answered by
funyun 958 Moderation Voter
8 years ago

Try a StringValue object.

--Script 1, named "Script1", located in a part, with a StringValue object called "name"
script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if player then
        script.name.Value = player.Name
        script.Parent.Script2.Disabled = false
    end
end)
--Script 2, named "Script2", disabled by default, also located in the part
print(script.Parent.Script1.name.Value)

Global variables (those located in _G) also work, but you want to avoid using them in most cases.

Answer this question