Script not processing instance from server

I’m trying to create a projectile but whenever I try to fire to the client to create effects on the client, I can’t send the projectile/instance to the clients.

instance as shown in the client script prints nil.

Server:

--Variables are above
local Basic = {}
Basic.__index = Basic

function Basic.new(player,pos,currentPoop)
	local self = setmetatable({},Basic)
	self.Player = player
	self.Character = player.Character
	self.Humanoid = self.Character.Humanoid
	self.Root = self.Character.HumanoidRootPart
	self.Part = Instance.new("Part")
	self.RayDir = pos
	self.CharactersTouched = {}
	self.CurrentPoop = currentPoop
	return self
end

function Basic:Hitbox()
	self.Part.Touched:Connect(function(hit)
		local character = hit.Parent
		local humanoid = character:FindFirstChild("Humanoid")
		if character and humanoid and not self.CharactersTouched[character] and character ~= self.Character then
			self.CharactersTouched[character] = character
			humanoid:TakeDamage(DAMAGE)
		end
	end)
end

function Basic:Destroy()
	task.delay(DESTROY_TIME,self.Part.Destroy,self.Part)
end

function Basic:Create()
	self.Part.Size = Vector3.new(2,2,2)
	self.Part.CanCollide = false
	self.Part.Anchored = true
	self.Part.Massless = true
	self.Part.Position = self.Root.Position + self.Root.CFrame.LookVector * 2
	self.Part.Parent = workspace
end

function Basic:Velocity()
	self.Part.AssemblyLinearVelocity = self.RayDir * 1000
end

function Basic:Init()
	self:Create()
	self:Hitbox()
	self:Velocity()
	self:Destroy()
	Remotes.ToClient:FireAllClients("FX",self.CurrentPoop,self.Part)
end

return Basic

Client:

Remotes.ToClient.OnClientEvent:Connect(function(signal,cp,instance)
	if signal == "FX" then
		print(cp,instance)
		Modules[cp].new(instance):Init()
	end
end)

Hello, I believe I know some approaches that will help you with this.

  1. When you want to create an instance on the client side based on server side information, rather than passing the instance itself, pass the essential information needed to create the instance on the cllint side. This information can include things like the position, size, properties, and other necessary stuff.

  2. On the client side, receive this information through RemoteEvents or RemoteFunctions, and use it to create the instance locally on the client.

The problem is I am using the part on the server for hitboxes.

I believe I have sent an instance created from the server to the client before so I don’t know why its not working now.

Hello, to combat this problem try this approach

  1. Send the information about the instance from the server to the client. This information can include the position, size, properties, and any other data.

  2. On the client side, receive this information and use it to create a representation of the instance.

An example of doing this is:

Server:

function Basic:Init()
    self:Create()
    self:Hitbox()
    self:Velocity()
    self:Destroy()
    Remotes.ToClient:FireAllClients("FX", self.CurrentPoop, self.Part.Position, self.Part.Size)
end

client:

Remotes.ToClient.OnClientEvent:Connect(function(signal, cp, position, size)
    if signal == "FX" then
        local newVisual = Instance.new("Part")
        newVisual.Size = size
        newVisual.Position = position
        newVisual.Color = Color3.fromRGB(255, 0, 0) -- Example color for visualization
        newVisual.Parent = workspace
    end
end)

I realized that when I turn off streaming enabled it works. I learned this from some posts:

Post 1
Post 2

The problem is, if I re-enable it, I have to use WaitForChild which I can’t do as “instance” is just a plain argument.

I don’t wanna recreate the part on the client and I already created it in create function.

Okay, achieve this by passing the instance’s NetworkInstanceId from the server to the client.

1 Like

I don’t know what you meant by NetworkInstanceId but I decided to use:

game:GetService(“HttpService”):GenerateGUID() and access its name from the client.

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