My game freeze and crash when script run

I was making skill that summon orb, It works fine in studio but not in game

https://sofargames.gyazo.com/64de8a425dbfaf9afc49fd676b24c902 (studio)
https://sofargames.gyazo.com/ce663f5e3d4dba9d86b7bdb4c0377530 (in game)

I know the problem is from the module that i use to make this effect but I not sure why
image

Here’s my module script

local TS = game:GetService(“TweenService”)

local trans = 1

local module = {}

module.DarkEffect = function (eTorso)
local HitEffect = script.DarkEffect:WaitForChild(“HitWave”)
local HitParticle = script.DarkEffect:WaitForChild(“HitModuleParticle”)
local HitParticle2 = script.DarkEffect:WaitForChild(“Effects2”)
local HitBall = script.DarkEffect:WaitForChild(“HitBall”)

local HiteffectBall = function(Pos)
local ClonedBall = HitEffect:Clone()
ClonedBall.Parent = workspace.SkillFX
ClonedBall.CFrame = Pos
ClonedBall.Color = Color3.fromRGB(18, 18, 18)
ClonedBall.CFrame = CFrame.new(ClonedBall.Position, eTorso.Position)
game.Debris:AddItem(ClonedBall,.4)

  local weld = Instance.new("WeldConstraint", ClonedBall)
  weld.Part1 = ClonedBall
  weld.Part0 = eTorso
  
  TS:Create(ClonedBall,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{CFrame = ClonedBall.CFrame + ClonedBall.CFrame.lookVector * -2,Transparency = trans,Size = Vector3.new(0.087, 0.08,0)}):Play()

end

local HitBallEffect = function(Pos)
local ClonedBall = HitBall:Clone()
ClonedBall.Parent = workspace.SkillFX
ClonedBall.CFrame = Pos
ClonedBall.Color = Color3.fromRGB(64, 0, 80)
ClonedBall.CFrame = CFrame.new(ClonedBall.Position, eTorso.Position)
game.Debris:AddItem(ClonedBall,.4)

  local weld = Instance.new("WeldConstraint", ClonedBall)
  weld.Part1 = ClonedBall
  weld.Part0 = eTorso
  
  TS:Create(ClonedBall,TweenInfo.new(0.4,Enum.EasingStyle.Quad,Enum.EasingDirection.Out),{CFrame = ClonedBall.CFrame + ClonedBall.CFrame.lookVector * -.6,Transparency = trans,Size = Vector3.new(0.087, 0.08, 2.35)}):Play()

end

spawn(function()
for i = 1,6 do
HitBallEffect(eTorso.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
HiteffectBall(eTorso.CFrame * CFrame.new(math.random(-1.3,1.3),math.random(-1.3,1.3),math.random(-1.3,1.3)))
end
end)

end

thx

edit: the module is required from the client side

2 Likes

probably a while loop without wait() somewhere in your code

1 Like

Just do wait(0.2) under every 6 lines and try to test again

spawn(function() is not a problem
loop without wait is not a problem
wait(0.2) under every 6 lines = still freezing

I’m confused why it’s work in studio but not in game

ignore it and call it a dev skill feature

You didn’t do getservice on debris

It works regardless. I always use game.Debris since its quicker. I know I shouldn’t, but oh well :sweat_smile:

game freeze and crash becuase the module was using too much memory?

have you at least tried? in the api reference it said this

Wdym have I tried? Yeah, I get that I should be using game:GetService("Debris"), and I know that game.Debris is bad practice. My point was to say that it works regardless, and that isn’t the cause of the memory issue.

Possibly… try adding print() statements and see where the script freezes.

1 Like

it crash at spawn function but if i remove it, it will just crash at the beginning

Hey, just took an in-depth look at your module. I don’t see how this could be crashing your game. There may possibly be exterior code doing such.

As a side note: I recommend cleaning up your code (properly indenting in post)

  • coroutine.wrap(function() > spawn(function()
1 Like

I tried making local script that require the module when i press key

https://sofargames.gyazo.com/4d02ee94ff01ef28ab6bf113bbb13050 (crash)

here’s the script (in case i type something wrong here)

  local UIS = game:GetService("UserInputService")
    UIS.InputBegan:Connect(function(Input)
    	if Input.KeyCode == Enum.KeyCode.N then
    		local plr = game.Players.LocalPlayer
    		local module = require(game.ReplicatedStorage.Modules.DarkMagicModule)
    		module.DarkEffect(plr.Character.HumanoidRootPart)
    	end	
    end)

edit : and summon script works fine without module

ok i got it, it was the weld constraint that make the game crash for some reason

1 Like