whyattJoin Date: 2008-05-23 Post Count: 2282 |
I am trying to refer to specific items in a system of folders within serverstorage. The problem is that the client can not directly refer to the ServerStorage. Therefore I index the items in the server storage.
I use a remote call to then get the server to clone items out of the server storage however I have no way to refer to the correct item because the referral is coming from the remote call from the client which cant carry a link.
I tried making the remote call carry the :GetFullName() of the child in the server storage that I am referring to however this wasn't working because :GetFullName() only givess a string value which cant be re-used to refer to a specific location.
if the above insn't clear enough
What i am trying to do is:
I have tools in server storage but not directly in it but different tools in different folders and the amouunt of folders varies.
A gui shop indexes a certain folder and these items can be clicked on the clients end.
A remote call sends to the server the name of the player and what item he clicked on.
The remote call need to then clone the correct item from server storage. <-- here is the problem (i cant refer to the item) If it was directly in server storage then yes i could send the item name along with it in the remote call however it in a complex series of folders to organise everything |
|
CasualistJoin Date: 2014-06-26 Post Count: 4443 |
" it in a complex series of folders to organise everything"
So if it's organized you should be able to find it. If you can't it's not organized.
That said, assuming everything has a unique name then
local tool = ServerStorage:FindFirstChild("UniqueToolName_Here", true)
if tool then
--// clone tool and do something with it
end
Should do the trick |
|
|
This is what happens when you guys keep telling noobs to use FE
>tries to access ServerStorage on client
>cant so decides to clone the object and send it using a RemoteFunction most likely
>doesnt work so he tries to access ServerStorage on client... again |
|
|
- Whar Are Filtiring Enabled?
- What Are Remote Functions ?
- What Are Remote Event ?
Can someone Explain ? or give a source thanks i am a noob |
|
|
FilteringEnabled decides if changes from the client should be replicated or not.
RemoteEvent - Similar to BindableEvents, but allow crossing the client/server boundary. This allows a Server Script to call code in a Local Script and vice versa. |
|
chimmihcJoin Date: 2014-09-01 Post Count: 17143 |
"This is what happens when you guys keep telling noobs to use FE
>tries to access ServerStorage on client
>cant so decides to clone the object and send it using a RemoteFunction most likely
>doesnt work so he tries to access ServerStorage on client... again"
FE has nothing to do with this, that doesn't work either way. |
|
pyth_nJoin Date: 2016-06-21 Post Count: 1322 |
replicatedstorage confirmed
- pyth_n |
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
Yo, so I need to use replicated storage? |
|
pyth_nJoin Date: 2016-06-21 Post Count: 1322 |
yes...
- pyth_n |
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
So do you mean i should copy the entire contents of the server storage into ReplicatedStorage?
Is replicated storage also in the local client? This would mean that the client would also have to load the entire serverstorage contents which im trying to bypass. I only want the client to load what it needs. |
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
Let me say this: getting to the serverstorage isnt the problem the problem is relaying back to the server the location of a specific item in the ServerStorage tree. The wiki doesn't reccomend i Parse the :GetFullName() data. |
|
pyth_nJoin Date: 2016-06-21 Post Count: 1322 |
ReplicatedStorage is on both the server and the client.
- pyth_n |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
This is the time to use remote functions.
--server script
local rf = game.ReplicatedStorage:WaitForChild('RemoteFunction')
function rf.OnServerInvoke:connect(function(plr,val)
local object = game.ServerStorage:FindFirstChild(val)
if object then
return object
end
end
--local script
local rf = game.ReplicatedStorage:WaitForChild('RemoteFunction')
local part = rf:InvokeServer('Part1')
if part then
print(part.Name)
end
|
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
Okay, but something i am struggling with is: Doesn't it defeat the purpose of the ServerStorage if I copy everything into the replicated storage?
Isn't it the point that only the server stores it so that the client can have smoother game-play without having to load things that are not being used? |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
RemoteFunctions.
--server
local rf = game.ReplicatedStorage:WaitForChild('RemoteFunction')
function rf.OnServerInvoke(plr,name)
local tool = game.ServerStorage:FindFirstChild(name)
if tool then
return tool
end
end
--client
local rf = game.ReplicatedStorage:WaitForChild('RemoteFunction')
local tool = rf:InvokeServer('Gun')
if tool then
print(tool.Name)
end
|
|
pyth_nJoin Date: 2016-06-21 Post Count: 1322 |
The client can't see anything that's not on the client;
and if you want to client to index it, it has to be on the client, doesn't it?
Makes no sense otherwise e.e
- pyth_n |
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
Yes, I know but i was trying to make it so that the client indexes only the specific thing they need with a remote function so that they don't have to index everything. But it seems that that is more complicating than it's worth. |
|
|
Just move the things you need indexed to replicated storage.
Unless you're a free model user, I don't see the problem here. |
|
TimeTicksJoin Date: 2011-04-27 Post Count: 27115 |
Its not clone complex. Just ask the server what tool the client wants,
check if the tool exists in serverstorage,
the server will then clone the tool into the players backpack.
Not that difficult to understand
|
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
I know, i'm trying to however make a general script where I can't refer to the specific location of the item inside the ServerStorage.
However i have already thought of a solution. When the game runs I will re-index everything into the root of the replicated storage with a randomised name (a number val that can easily be tranferred)
This would actually also work if I use the ServerStorage |
|
whyattJoin Date: 2008-05-23 Post Count: 2282 |
And it ended up not working as smoothly as i wanted due to some of the randomized values being the same because they run at the same time.
|
|
|
what some person said somewhere above (too lazy to look at who wrote it)
FindFirstChild has an optional second argument, recursive
it makes FindFirstChild look through the children of the object
so say you use folder:FindFirstChild('hello')
folder
->1
->hello
->2
it would return nil here
but folder:FindFirstChild('hello',true) --second is the recursive (bool) would return the hello object
|
|