Mouse.Hit.Position is being detected as an Instance

I’m scripting a grenade for my game and I’m encountering an error where Mouse.Hit.Position is being detected as an instance.

local script

local triggered = false

local throwanim = Instance.new("Animation")
throwanim.AnimationId = "rbxassetid://109507443120253"

local Throw = script.Parent.Parent.Parent.Character.Humanoid.Animator:LoadAnimation(throwanim)

script.Parent.Activated:Connect(function()
	if not triggered then
		local mouse = game.Players.LocalPlayer:GetMouse()
		triggered = true
		Throw:Play()
		wait(0.6)
		script.Parent.ThrowEvent:FireServer(mouse.Hit)
		print("Activated")
		wait(20)
		script.Parent.RegenEvent:FireServer()
		triggered = false
	end
end)

server script

script.Parent.ThrowEvent.OnServerEvent:Connect(function(mouse)
	local nade = script.Parent:Clone()
	local mousePos = mouse
	nade.Parent = workspace
	for _, child in ipairs(nade:GetChildren()) do
		if child:IsA("BasePart") and child.Name ~= "Pin" then
			child.CanCollide = true
		elseif child:IsA("BasePart") and child.Name == "Pin" then
			child.Transparency = 1
		elseif child:IsA("Script") or child:IsA("LocalScript") then
			child.Enabled = false
		end
	end
	nade.BodyAttach:ApplyImpulse((nade.BodyAttach.Position - mousePos) * Vector3.new(throwforce, throwforce*6, throwforce))
	for _, child in ipairs(script.Parent:GetChildren()) do
		if child:IsA("BasePart") then
			child.Transparency = 1
		end
	end
	wait(5)
	local pos = nade.BodyAttach.Position
	
	local hitreg = rp.ExplosionStuff.GrenadeExplosion.HitReg:Clone()
	local ragreg = rp.ExplosionStuff.GrenadeExplosion.RagReg:Clone()
	local particles = rp.ExplosionStuff.GrenadeExplosion.Particles:Clone()
	hitreg.Parent = workspace
	hitreg.Position = pos
	ragreg.Parent = workspace
	ragreg.Position = pos
	particles.Parent = workspace
	particles.Position = pos
	hitrregister(hitreg)
	RagdollRegister(ragreg)
	hitreg.SFX:Play()
	wait(0.1)
	nade:Destroy()
	particles.ParticleEmitter:Emit(50)
end)

Receiving this error:
image_2025-03-01_232013385

Am I doing something wrong or is this some obscure bug?

what is throwforce? that’s the only thing i could see on this script about making a new vector3

OnServerEvent’s first argument is the Player object of the person who fired the RemoteEvent, so you just need to add an extra parameter at the front of your function.

script.Parent.ThrowEvent.OnServerEvent:Connect(function(player, mouse)

end)
1 Like

I agree with @MysteriousVagabond, but I’d also like to mention that you’re sending mouse.Hit rather than mouse.Hit.Position when firing the remote event.

1 Like

throwforce is something at the top of my server script, it just equals 5. I didnt include it because my server handler is quite long and i wanted to isolated it to where the problem was.

It’s still detecting mouse.Hit.Position as an instance

thats from my various troubleshooting that i forgot to clean up, apologies

Replace this line with this

script.Parent.ThrowEvent.OnServerEvent:Connect(function(evPlr, mouse)

This is correct.

Here is why it is correct:
You can send an argument whenever you use a remote event. It looks like you’ve sent the mouse.Hit through.

However, when you receive an argument on the server, using OnServerEvent:Connect(function(.., it actually adds another argument before the arguments that you passed through.
That extra argument is the player, and it always comes first.

So, this code is fine:

script.Parent.ThrowEvent:FireServer(mouse.Hit)

But this code isn’t:

script.Parent.ThrowEvent.OnServerEvent:Connect(function(mouse)

This is because it is expecting to receive two properties as I explained. The player, first, and then the mouse. So, it is a very simple correction.

Thank you guys, I would have never guessed that ;-;

1 Like

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