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)
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
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.
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