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:
Am I doing something wrong or is this some obscure bug?