Onclientevent parameter being recieved as "nil"

I’m trying to make a system in which a ball spawns in, and chooses a random target. At the moment I’m working on the targeting part of the script. I’m currently trying to send the Ball to the client so that the client can edit the ball’s properties. The main issue is that the parameters are being received as “nil.” The ball is located in the Workspace, and I’ve checked, but I haven’t been able to find a solution to this problem.

Client code:

local CAS = game:GetService(“ContextActionService”)
local Sword_Event = game:GetService(“ReplicatedStorage”):WaitForChild(“Sword_Events”):WaitForChild(“Sword_Event”)
local On_Target = game:GetService(“ReplicatedStorage”):WaitForChild(“On_Target”)

print(“Ball”) – printed as “nil”

Server code:

local On_Target = game:GetService(“ReplicatedStorage”):WaitForChild(“On_Target”)
local Ball = script.Parent
local Target = Ball:WaitForChild(“Target”)

local Character = Target.Value

local Player = game.Players:GetPlayerFromCharacter(Character)

On_Target:FireClient(Player, Ball)



Non-Replicated Instances

If a RemoteEvent or RemoteFunction passes a value that’s only visible to the sender, Roblox doesn’t replicate it across the client-server boundary and passes nil instead of the value. For example, if a Script passes a descendant of ServerStorage, the client listening to the event will receive a nil value because that object isn’t replicable for the client.


but the ball is in the workspace?

1 Like

isn’t this supposed to be print(Ball)??? adding “” just prints text for me

1 Like

oh ye it’s supposed to be print(ball) but that’s where it’s “nil”

Just try to print out a string, like print(Ball.Name)
Since yeah, Ball is an object.

It may be that the ball is not being replicated in time when the event is received on the client.

Try this pattern:

Ball.Parent = workspace

   On_Target:FireClient(Player, Ball)

Edit: it may need to be task.delay(0, function() … end) instead actually so worth trying both