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”)
On_Target.OnClientEvent:Connect(function(Ball)
print(“Ball”) – printed as “nil”
end)
Server code:
local On_Target = game:GetService(“ReplicatedStorage”):WaitForChild(“On_Target”)
local Ball = script.Parent
local Target = Ball:WaitForChild(“Target”)
Target.Changed:Connect(function()
local Character = Target.Value
print(Character.ClassName)
local Player = game.Players:GetPlayerFromCharacter(Character)
print(Player)
print(Ball.Parent)
On_Target:FireClient(Player, Ball)
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.
You might have to use task.delay(0.05, function) because it APPARENTLY takes more than a frame for a part created on the server to replicate to the client. This is INCREDIBLY annoying since the time it takes for the server to replicate anything to the client is variable so using task.delay might error on the client if they’re lagging enough. I am currently facing the same issue and have NOT solved it.