Disable the debris on the player activating the tool

I have a script that is launching a grenade, using the debris system but if I aim on the ground, the player gets killed (the other players and the local player) but I only want the other players to get hit by the explosion of the grenade.

Here is the local script in “StartPlayerScripts” :

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
	local rocket = game.ReplicatedStorage.Rocket:Clone()
	rocket.Parent = workspace
	rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)

	local bv = Instance.new("BodyVelocity", rocket)
	bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100

	rocket.Touched:Connect(function(hit)
		if hit:IsA("BasePart") then
			if hit.Parent ~= tool then
				rocket:Destroy()
				game.ReplicatedStorage.Fire:FireServer(rocket.Position, mouseHit)
			end
		end
		debris:AddItem(rocket, 3)
	end)
end)

And this is the Server Script in “ServerScriptService” :

local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(plr, rocketPos, mouseHit)
	local explosionPart = Instance.new("Part", workspace)
	explosionPart.Anchored = true
	explosionPart.CanCollide = false
	explosionPart.Transparency = 1
	explosionPart.Position = rocketPos
	local expoSound = game.ReplicatedStorage.ExplosionSound:Clone()
	expoSound.Parent = explosionPart
	expoSound:Play()



	local explosion = Instance.new("Explosion", workspace)
	explosion.Position = explosionPart.Position
	debris:AddItem(explosionPart, 3)
end)

The scripts of the Tool are just the animations and the events.

Check out the docs on the Explosion instance. You can disable damage from the explosion and use the event explosion.Hit to detect the items hit from the explosion (which you can then filter out to damage players):

I don’t really know how to use it and the docs didn’t help me

You could add a conditional statement in the server script to check if the affected player is the local player. If it is, then you can skip the explosion logic.

if plr == game.Players.LocalPlayer then
	return
end

But server scripts can’t access to game.Players.LocalPlayer

You can pass the player’s identifier as a parameter when calling the server function and compare it to the userId of the local player on the server side.

--Local Script in "StartPlayerScripts"
local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnClientEvent:Connect(function(plr, mouseHit, tool)
local localPlayer = game.Players.LocalPlayer
local rocket = game.ReplicatedStorage.Rocket:Clone()
rocket.Parent = workspace
rocket.CFrame = CFrame.new(tool.RocketHole.Position, mouseHit)

local bv = Instance.new("BodyVelocity", rocket)
bv.Velocity = CFrame.new(rocket.Position, mouseHit).LookVector * 100

rocket.Touched:Connect(function(hit)
	if hit:IsA("BasePart") then
		if hit.Parent ~= tool then
			rocket:Destroy()
			game.ReplicatedStorage.Fire:FireServer(localPlayer.UserId, rocket.Position, mouseHit)
		end
	end
	debris:AddItem(rocket, 3)
end)
end)

--Server Script in "ServerScriptService"
local debris = game:GetService("Debris")

game.ReplicatedStorage.Fire.OnServerEvent:Connect(function(playerId, rocketPos, mouseHit)
local player = game.Players:GetPlayerByUserId(playerId)
if player == game.Players.LocalPlayer then
return
end
local explosionPart = Instance.new("Part", workspace)
explosionPart.Anchored = true
explosionPart.CanCollide = false
explosionPart.Transparency = 1
explosionPart.Position = rocketPos
local expoSound = game.ReplicatedStorage.ExplosionSound:Clone()
expoSound.Parent = explosionPart
expoSound:Play()

local explosion = Instance.new("Explosion", workspace)
explosion.Position = explosionPart.Position
debris:AddItem(explosionPart, 3)
end)

Now I have this error “Unable to cast Instance to int64” on this line :

local player = game.Players:GetPlayerByUserId(playerId)
local player = game.Players:GetPlayerByUserId(tonumber(playerId) + 0LL)

Try this

Now it’s exploding but it’s not damaging, there is no blast pressure and I have this error : “Malformed Number

Its still not working, it’s not exploding at all