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

How do I use values in other scripts?

Asked by
lucas4114 607 Moderation Voter
9 years ago

So in one script in a model, I set a value: health = 10 So then in a different script I want to change that for something and I try to get to the value like this: script.Parent.Parent.Script.health It didn't work. How do I get to values in other scripts?

1
You can either set the value to an IntValue or use Global Variables. In your other script put _G.health = 10 and then in the other script you wanna use it just do local health = _G.health and it should work fine. 0xDEADC0DE 310 — 9y

1 answer

Log in to vote
2
Answered by
RM0d 305 Moderation Voter
9 years ago

I would store them as int values or number values.

at the top of script do

a script in workspace named 'healthScript'

local health = Instance.new("NumberValue",script) 
health.Name = "health"
health.Value = 10

health.Changed:connect(function () print(health.Value) end)

a script in workspace

workspace.healthScript.health.Value = 5

This should print 5

Update: was half asleep and workspace is a bad idea to store scripts however thanks for adark pointing it out!

** Just a tip, it is bad practice to put Scripts in the Workspace. It's much safer to put them in the ServerScriptService. ** ~ adark

0
Just a tip, it is bad practice to put Scripts in the Workspace. It's much safer to put them in the ServerScriptService. adark 5487 — 9y
0
Yer I know, however instead of faking a path I just used workspace out of the flash. Thanks anyhow. RM0d 305 — 9y
Ad

Answer this question