Several issues when using a ModuleScript

I’ve made a ModuleScript that I like to use on friends.
It spawns a nuke 10k studs in the air, and when firing an event it starts to fall down.

Upon testing it in studio, it works as expected. Nothing is wrong.
However, some issues have arisen when testing through the player.
For example:

  • The R15 rig dies from explosions, but the R6 rig doesn’t.
  • In games with a large number of parts, Instance.new() fails to create the explosion.

I haven’t got a clue as to why both of these things are happening.
Any help would be appreciated!

3 Likes

Are you using explosion instance ?

if so then you need created your own system explosion with whatever-casts (recommeding using workspace to fire the Method, doesn’t need Instance.new())

if you want constenst explosion, fire the SphereCast alot (in different position(-s), if you want bombarding) because it’s fired

make sure part are touched by SphereCast, not intersected

WorldRoot - SphereCast | Documentation - Roblox Creator Hub

if you don’t want this then share with us your code, we may notice the flaws

What a hassle just for dropping a bomb on someone’s head.
I can see why you ran into issues.

Module
--ModuleScript in ReplicatedStorage named NukeModule
local Nuke={}
function Nuke.Spawn(targetPos, ignorePlayer)
	local n=Instance.new("Part")
	n.Size=Vector3.new(4,4,4)
	n.Position=targetPos+Vector3.new(0,500,0)
	n.Anchored=true
	n.CanCollide=false
	n.Shape=Enum.PartType.Ball
	n.BrickColor=BrickColor.new("Really red")
	n.Material=Enum.Material.Neon
	n.Parent=workspace

	task.spawn(function()
		local speed=0
		while n.Position.Y > targetPos.Y do
			local dt=task.wait()
			speed=speed+9.81*dt*5
			n.Position=n.Position-Vector3.new(0,speed*dt,0)
		end

		local explosion=Instance.new("Explosion")
		explosion.Position=n.Position
		explosion.BlastRadius=50
		explosion.BlastPressure=200000
		explosion.ExplosionType=Enum.ExplosionType.NoCraters
		explosion.Parent=workspace

		explosion.Hit:Connect(function(p)
			if ignorePlayer and p:IsDescendantOf(ignorePlayer.Character) then return end
			local h=p:FindFirstAncestorOfClass("Model") and p:FindFirstAncestorOfClass("Model"):FindFirstChildOfClass("Humanoid")
			if h then h:TakeDamage(100) end
		end)

		task.spawn(function()
			task.wait(1)
			explosion:Destroy()
			n:Destroy()
		end)
	end)
end
return Nuke

A way to trigger it to test with

ServerScript
--ServerScript in ServerScriptService
local ReplicatedStorage=game:GetService("ReplicatedStorage")
local ev=ReplicatedStorage:FindFirstChild("NukeEvent") or Instance.new("RemoteEvent",ReplicatedStorage)
ev.Name="NukeEvent"
local Nuke=require(ReplicatedStorage:WaitForChild("NukeModule"))
ev.OnServerEvent:Connect(function(player,targetPos)
	Nuke.Spawn(targetPos, player)
end)
LocalScript
--LocalScript in StarterPlayerScripts
local ReplicatedStorage=game:GetService("ReplicatedStorage")
local UserInputService=game:GetService("UserInputService")
local ev=ReplicatedStorage:WaitForChild("NukeEvent")
local player=game.Players.LocalPlayer
UserInputService.InputBegan:Connect(function(i,processed)
	if processed then return end
	if i.KeyCode==Enum.KeyCode.E then
		local pos=player.Character and player.Character.PrimaryPart and player.Character.PrimaryPart.Position or Vector3.new()
		ev:FireServer(pos)
	end
end)

Had it working right away, but I could not get rid of the engine flashing that red bar to indicate potential high-impact damage or network stress. Finally, I got it working.

I’ve never even seen that until now. Nuke blues I guess.
Pretty sure the whole area is going to go up in flames. :rofl:
May be a whole lot of overkill here.

This has fixed my issue! Thanks a lot!
(took a little bit of the code and rammed it into mine, it works perfectly fine now!)

1 Like

Actually figure you would be able to do that. Sweet

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