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

Make variables(values) shared, but only between SOME scripts?

Asked by
kazeks123 195
7 years ago

I have multiple LocalScripts that are inside a player model, but what I have intended won't work unless there's a way to make thouse scripts' variables(values) available through all of them, but not through anything else. Also I want thouse scripts to still function properly even if i clone them to different players on the same game, same server.

For example, I want to be able to do something like this:

Script1: local x = 1

Script2: local x = script.Parent.Script1.variable(x) print(x)

Output: Script2: 1

Of course there is a reason why I can't simply make the variable inside the same script. It's because the variable will be modified by a loop and I already have a loop inside the script in which I would want to have that variable(value).

I've heard of a method that would make the variable available to all scripts, but if it is cloned, then there'll be just a mess of multiple same name variables with different values.

0
Why not put the variable inside a StringValue which all the local script can access? addictedroblox1414 166 — 7y

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago
Edited 7 years ago

This is usually a bad idea because it's very confusing and easy to mess up.

ROBLOX gives you controlled ways for scripts to communicate with each other.

ModuleScripts let you define a script that "exports" an interface to different scripts. The object is shared among all server scripts / all localscripts on a given client, which means you can share local variables however you want, usually behind functions.

BindableFunctions are another way for scripts to talk to each other using functions.

You could also use plain old IntValue, ObjectValue, StringValue, etc. objects, but these are only the right way to organize your code from time-to-time.


If you explain specifically the kind of information you want to share, I could suggest a manageable way to set up your scripts.

0
I'm already giving up on my intention, because it seems that no matter what I try to do Roblox will always find a way to break it. I was trying to do things that seem to be too complicated for Roblox to handle thus I shall start a much simpler project. I haven't done any research on modulescripts or bindable functions, but it might be the answer for someone else looking to solve this problem. kazeks123 195 — 7y
0
If you're still wondering what I was trying to do then it was creating somewhat of a realistic vehicle physics, such as, having rpm go up or down depending on player's inputs or accelerating slower or faster depending on the gear that the player has choosen. In th end all of theese things require loops to update their values and, so I wanted them to be split amongst many scripts, but it no longer kazeks123 195 — 7y
Ad

Answer this question