jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
|
| 08 Jan 2013 09:49 PM |
I've been trying for hours to get this script of mine to work. Whenever I place a shared.sometable in front of it, it won't work. I'm guessing that localscripts cannot call shared?
I apologize for posting here, but few people in SH want to help :< |
|
|
| Report Abuse |
|
|
Waffle3z
|
  |
| Joined: 15 Apr 2011 |
| Total Posts: 266 |
|
|
| 08 Jan 2013 09:55 PM |
| Shared is a global table like _G, which can't be accessed from the client. |
|
|
| Report Abuse |
|
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
| |
|
Waffle3z
|
  |
| Joined: 15 Apr 2011 |
| Total Posts: 266 |
|
|
| 08 Jan 2013 09:58 PM |
| It can, however, trigger an event in a separate server-sided script to do what you want. |
|
|
| Report Abuse |
|
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 08 Jan 2013 10:08 PM |
| Each instance of the ROBLOX client has a separate instance of shared and _G. So you can't use those tables to send data from client to server or vice versa. |
|
|
| Report Abuse |
|
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
| |
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
| |
|
jrf2112
|
  |
| Joined: 29 Jun 2008 |
| Total Posts: 3354 |
|
|
| 08 Jan 2013 10:10 PM |
| Intelligent, knowledgeable. |
|
|
| Report Abuse |
|
|
Garnished
|
  |
| Joined: 09 Apr 2012 |
| Total Posts: 12695 |
|
|
| 08 Jan 2013 10:16 PM |
| no, we just say stuff and expect people to think we know what we're saying |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 08 Jan 2013 10:31 PM |
Actually, LocalScripts can call shared!
setmetatable(shared, { __call = function() print("shared has been called") end }) shared() |
|
|
| Report Abuse |
|
|
Garnished
|
  |
| Joined: 09 Apr 2012 |
| Total Posts: 12695 |
|
|
| 08 Jan 2013 10:36 PM |
^ output = error on line 1 nub |
|
|
| Report Abuse |
|
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
|
| 08 Jan 2013 11:55 PM |
| Well you can use shared, thought it will be accessable by local scripts only. |
|
|
| Report Abuse |
|
|
NVI
|
  |
| Joined: 11 Jan 2009 |
| Total Posts: 4744 |
|
|
| 09 Jan 2013 06:00 PM |
> You people are smert.
Not really. This is common sense. How can you expect to access memory that's on a different computer entirely? This is why Roblox scripting is bad - kids come away thinking replication is magic and automatic. |
|
|
| Report Abuse |
|
|
noliCAIKS
|
  |
| Joined: 08 Mar 2010 |
| Total Posts: 917 |
|
|
| 11 Jan 2013 10:46 AM |
I made something to get shared working across multiple clients. Simply put this in a normal script in the Workspace and in a local script in the StarterPack:
if shared.SetValue then script:Destroy() else script.Parent = nil end
local changedSignal = LoadLibrary("RbxUtility").CreateSignal() local lighting = game:GetService("Lighting") local repository = lighting:FindFirstChild("Shared Repository") if repository then for index, child in ipairs(repository:GetChildren()) do shared[child.Name] = child.Value end else repository = Instance.new("Model", lighting) repository.Archivable = false repository.Name = "Shared Repository" end repository.ChildAdded:connect(function(child) local name, value = child.Name, child.Value shared[name] = value changedSignal:fire(name, value) end) shared.Changed = changedSignal function shared.SetValue(type, name, value) local oldObject = repository:FindFirstChild(name) local object = Instance.new(type .. "Value") object.Name = name object.Value = value object.Parent = repository if oldObject then oldObject:Remove() end end
In other scripts that use shared, put this at the start of the script:
while not shared.SetValue do wait() end
Then, to use shared, simply use this: shared.SetValue(type name, variable name, value) Some examples: shared.SetValue("Number", "numberThree", 3) shared.SetValue("BrickColor", "favoriteColor", BrickColor.White()) print(shared.numberThree) -- 3 print(shared.favoriteColor) -- White
If you want to wait for a value to change or be notified immeadiately when a value changes, use this: local key, value = shared.Changed:wait() print(key, value) -- some variable, some value
shared.Changed:connect(function(key, value) print(key, value) -- some variable, some value end)
That's all! |
|
|
| Report Abuse |
|
|