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

Is there a way to Transfer a Variable from Server to Client?

Asked by 4 years ago

Hello,

Is there a possible way to Transfer a Variable from Server to Client?

With RemoteEvents its not working because

Dev Wiki

Non-replicated Instances If the value being sent is only visible to the sender then nil will be passed instead of the value. For example, if a server tries to pass a descendant of ServerStorage, the client listening to the event will see nil passed as the value.

local part = Instance.new("Part", ServerStorage)
remoteEvent:FireClient(player, part)

In the above code, when the client receives the event it will only see nil passed in and will not have reference to the part.

Any Ideas?

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Not sure what your end goal is. I can think of two things your end goal may be.

1 You want a part to be seen by only the client: Put the part into ReplicatedStorage, that way, the client already has access to it and it can make it's own instance of the part inside of a Local Script.

2 You want everyone to eventually see the part: Create the part inside of a server script and then pass the part to the client.

3 You want to send the client a secret part that it doesn't have access to: Why would you want to do this? This is what you are doing now and why the Local Script is seeing nil.

Ad
Log in to vote
0
Answered by 4 years ago

Example:

--[[Script]]--
local Players = game:GetService("Players")

local function onPlayerAdded(player)
    remoteEvent:FireClient(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)


-- ========================================


--[[LocalScript]]-- 

local function Test()
local part = Instance.new("Part", ServerStorage)
part.Name = "PartTestRemoteEvent"
end

remoteEvent.OnClientEvent:Connect(Test)

Answer this question