Variable from script doesn't transfer to the local script

I want a variable from a script located in the ServerScriptService to transfer to a local script by firing a remote event but for some reason the variable doesn’t get recognised.

Script in ServiceScriptService :

Local Script :
image

Output after asked to print the variable “DroneCam” name :

1 Like

OnClientEvent Doesn’t Pass The Player Argument Like OnServerEvent Does.

ChangeCam.OnClientEvent:Connect(function(DroneCam)

end)

You only need to pass the player from :FireClient once

ChangeCam:FireClient(plr, DroneCam)
1 Like

And also I would Change plr:HasAppearanceLoaded() as that would fail if ROBLOX fails to load someones avatar and makes them a noob.

local loadChar = (plr.Character ~= nil)

if loadChar == true then

end
1 Like

I am so sorry I misread your code!

Hello. Thank you for your response! I’ve modified the script following your instructions but I still end up with the same output.


image

Its because the script is failing to find “DroneCam” so instead of passing an instance, it just passes nil

Does the server script print Drone.Name?

Yes the server script does print DroneCam.Name

How could I make the script find “DroneCam”

You could alternatively pass through a cframe value to the client instead of the part (considering that’s what you’re doing), unless you’ll specifically need the player’s camera to follow the drone.

Yes, the point of having the Camera part is for the player’s camera to follow the drone.

Add a task.wait(2) to your server script just to make sure that the part has time to load in on the client. If that works, you might want to use WaitForChild so that the server isn’t forced to yield any longer than it needs to be.

It’s essential to use WaitForChild here, because the RemoteEvent is almost always going to get to the client before the DroneCopy instance has replicated to the client.

In the server Script, DroneCopy:WaitForChild(“Owner”) is not necessary, when you Clone() an instance, all of its descendants are also cloned and immediately available to reference on the next line of code.

1 Like

Thanks for the info, I’ll remove the WaitForChild!

I added the task.wait and it works! Thank you very much for your response!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.