BindableEvent returns nil on parameters

So I’m making a FPS framework, and I want the bullet effects to be handled on the client instead of the server to prevent lag.

Here’s my code linked for the bindableevent:

local repbh = game:GetService('ReplicatedStorage'):WaitForChild('Replication'):WaitForChild('ReplicateBH_Client')
local debris = game:GetService('Debris')

repbh.Event:Connect(function(plr,muzcf,pos)
	local bh = game.ReplicatedStorage.Effects.BulletHole:Clone()
	bh.Parent = workspace
	bh.CFrame = muzcf
	bh.Transparency = 1
	debris:AddItem(bh,1)
	task.delay(0,function()
		bh.CFrame = CFrame.new(pos)
		bh.Transparency = 0
		bh.Attachment0.TrailParticles.Enabled = false
		for i = 0,1,.1 do
			bh.Transparency = i
			task.wait()
		end
	end)		
end)

pos is always nil. muzcf is fixed by doing bh.Position = muzcf (which I don’t know why since it retunrs a CFrame and not Vector3??)

Error (the numbers are pos, and it’s not nil):

This is the gun’s code:

replicatedstorage.Replication.ReplicateBH_Client:Fire(muzzle.CFrame,pos)

muzzle.CFrame is the gun’s muzzle point, or where it fires the bullet out of.
pos is the raycast’s landing point.

Am I missing something?? BindableEvents have never done this to me.

Hello, may I see the full script of where that line of code was at? There may be something not right with pos.

I’m not comfortable with sharing all my code (plus its like 1000 lines almost), but here’s the raycast part:

	local ray = Ray.new(muzzle.CFrame.p,muzzle.CFrame.lookVector*999)
	local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{c})

(c is the character)

Ok, maybe try using the hit variable and make

local pos = hit.Position

Does that make a difference?

New:

storage.Replication.ReplicateBH_Client:Fire(muzzle.CFrame,pos.Position)

Wait. That said that the pos value before you put .Position it was a Vector3 value. maybe remove that .Position and see what happens.

I didn’t know why it returned a CFrame value in the first place.

I may think that it was referring to another set of arguments in another line of code.

Well it’ll do the same thing as before. I also just tried returning the muzzle part instead… and…

HUH

I think now I understood what went wrong. In the replication script, you had a first parameter of the plr variable. When you tried firing the bindable function, were you also going to add the player to the set on arguments on:

replicatedstorage.Replication.ReplicateBH_Client:Fire(muzzle.CFrame,pos)

Here is what I was imagining:

replicatedstorage.Replication.ReplicateBH_Client:Fire(**player**,muzzle.CFrame,pos)

Since you didn’t add the plr variable, the script confused the 2nd parameter with the pos and not the CFrame value.

Don’t tell me that was all it was…

Yep that was it.

Sorry I gave you unnecessary advice at first, I needed to break down what was happening by using debugging strategies.

1 Like