Explosion not working

So I was trying to implement a way to get a badge by clicking on an model’s head and then it explodes, disappearing after a few seconds. I want it so that the player can only see that happen as well.

For some reason though, the explosion works but the model just stays there for a moment and then all the body parts scatter, staying in place.

I checked to see if they were anchored, but they weren’t, besides the humanoid root part. If someone can help me or tell me what I did wrong, and show me a solution, that’d be nice.

Server-sided script:

local BadgeService = game:GetService("BadgeService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local badgeId = 2148960822

function HandleHealth(monster)

	monster.Humanoid.Health = 0
end

local ClickEvent = Instance.new("RemoteEvent")
ClickEvent.Name = "ClickEvent"
ClickEvent.Parent = ReplicatedStorage

ClickEvent.OnServerEvent:Connect(function(player)
	local hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, badgeId)

	if not hasBadge then
		BadgeService:AwardBadge(player.UserId, badgeId)
			print("Player recieved badge")

		HandleHealth(game.Workspace.Monster1)
	end
end)

Client-Sided Script:

local player = game.Players.LocalPlayer
local monster = game.Workspace.Monster1

local function HandleExplosion()

	local explosion = Instance.new("Explosion")
	explosion.Position = monster.Head.Position
	explosion.Parent = game.Workspace
end

monster.Head.ClickDetector.MouseClick:Connect(function()

	game.ReplicatedStorage.ClickEvent:FireServer()


	HandleExplosion()
end)

Result:
image

1 Like

Creating the explosion on the server rather than the client might fix this issue

Hey @Mini_StampyYT52 , I understand that your goal is to make the model disappear after the explosion, if so you need to add a destroy():

local player = game.Players.LocalPlayer
local monster = game.Workspace.Monster1

local function HandleExplosion()

	local explosion = Instance.new("Explosion")
	explosion.Position = monster.Head.Position
	explosion.Parent = game.Workspace

    task.wait(1)

    monster:Destroy()

end

monster.Head.ClickDetector.MouseClick:Connect(function()
--staff
    game.ReplicatedStorage.ClickEvent:FireServer()
	HandleExplosion()
end)

When it comes to executing the script on the client side only, don’t use RemoteEvent for that, because you are sending information to the server, and your goal is to reproduce it locally for the player

Would I put this in the server script or local script?

If you only want the script to be executed for a local player it must be a local script

I disabled the server script and used your script as a local script and it had the same results afterwards.

Are you sure you typed monster:destroy() or any errors in the console?

Well, I did now, my mistake. But I kinda wanted to have the body parts fly (they did but it just froze in place afterwards) instead of it just disappearing, then give the player the badge for doing so. I know badges can only be implemented on a server or module script though.

And as for the badge, you can not use module scripts for local scripts, alternatively you can use a normal script.

Alternatively, you can still do this

local player = game.Players.LocalPlayer
local monster = game.Workspace.Monster1

local function HandleExplosion()

	local explosion = Instance.new("Explosion")
	explosion.Position = monster.Head.Position
    explosion.ExplosionType = Enum.ExplosionType.NoCraters
    explosion.DestroyJointRadiusPercent = 0
	explosion.Parent = game.Workspace

    task.wait(1)

    monster:Destroy()
end)

monster.Head.ClickDetector.MouseClick:Connect(function()
--staff
    game.ReplicatedStorage.ClickEvent:FireServer()
	HandleExplosion()
end)

Hey so uh, I went to new place to see what i was dealing with, and I found out this happens? I can’t tell if it is lag or there’s something going on

What I did:

local player = game.Players.LocalPlayer
local monster = game.Workspace.Mini_StampyYT52
local Clickdetector = monster:WaitForChild("Head").ClickDetector

local function HandleExplosion()

	local explosion = Instance.new("Explosion")
	explosion.Position = monster.Head.Position
	explosion.Parent = game.Workspace

	task.wait(1)

	monster.Humanoid.Health = 0

end

Clickdetector.MouseClick:Connect(function()
	--staff
	game.ReplicatedStorage.ClickEvent:FireServer()
	HandleExplosion()
end)

Try adding this piece of code (explosion:Destroy() I would recommend adding this line of code so that the created explosion removes itself after the action is executed, because why should it lie around and take up space in the workspace.)

Final code after changes

As a last resort, you can try with this

monster:SetNetworkOwner() --SERVER will ALWAYS simulate physics of a part

I’m sorry, but I currently have no way to check if a particular code is working because I’m not in my house and don’t have access to a studio

Hey, sorry I took long to respond back, but I seem to got it working. Thanks!

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