generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Can localscripts not call shared?

Previous Thread :: Next Thread 
jrf2112 is not online. 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 is not online. 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 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
08 Jan 2013 09:56 PM
Ah. Crap.
Report Abuse
Waffle3z is not online. 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
untamedangel44 is not online. untamedangel44
Joined: 06 May 2012
Total Posts: 1900
08 Jan 2013 10:02 PM
hellu, r u ok
Report Abuse
Seranok is not online. 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 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
08 Jan 2013 10:09 PM
You people are smert.
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
08 Jan 2013 10:09 PM
Not really.
Report Abuse
jrf2112 is not online. jrf2112
Joined: 29 Jun 2008
Total Posts: 3354
08 Jan 2013 10:10 PM
Intelligent, knowledgeable.
Report Abuse
Garnished is not online. 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 is not online. 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 is not online. Garnished
Joined: 09 Apr 2012
Total Posts: 12695
08 Jan 2013 10:36 PM
^
output = error on line 1
nub
Report Abuse
untamedangel44 is not online. untamedangel44
Joined: 06 May 2012
Total Posts: 1900
08 Jan 2013 11:15 PM
k
Report Abuse
zars15 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image