Remote event sends nil instead of part

-- server script
local player = game.Players.PlayerAdded:Wait()
task.wait(5) -- remove other factors such as game loading in
local part = Instance.new("Part")
part.Name = "SpecialThing"
part.Parent = workspace
game.ReplicatedStorage.RemoteEvent:FireAllClients(part)
print("Fired", player, part)
--client script
game.ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function(p)
	print(workspace:WaitForChild("SpecialThing"))
	print(p)
end)
print("initialized client")

output
image
the weird thing is, if I add a task.wait() before I fire on the server, the part isn’t nil
I could slap on a task.wait() and ignore this but I want to know why it happens and if there’s any way around a task.wait()
problem is that the parameter p is nil, but part exists on the client

I don’t think that’s right. If I prefix the remote event fire with a task.wait() p will get printed out fine
image

1 Like

image
Definitely prints the part

You can send instances.

This is most likely a StreamingEnabled problem, your parts don’t have enough time to load on the client for them to register in the RemoteEvent.

2 Likes

but the print(workspace:WaitForChild(“SpecialThing”)) working means that it exists on the client

The instance first gets sent in at nil, and your wait is after it is already set to nil. The instance variable doesn’t become anything other than nil after it was already set.

ohhhhhhhhhhhhhhhhhhh
ok thank you!

do you know of any workarounds so that I can send in instances from the server to the client?

You could put the part in a model and set the model’s streaming mode to persistent. It is not performant, but it will fix your problem.

2 Likes

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