My game is crashing even when I play the game in studio

Whenever I play my game and place a tower it crashes. How is it happening?

It could be the code that’s executing when place a tower down? That seems like the likely candidate, may we see your code that executes when you place a tower?

Whenever I place it and the tower shoots, it crashes.

Could it be the code that fires when the tower shoots?

This is the code if you’re wanting it

local function dmg(part)
	if not attackdeb then
		while enemyinzone do
			if part.Parent.Humanoid.Health > 0 then
			script.Parent.HumanoidRootPart.pistol_shoot:Play()
			local CharRoot = script.Parent.Torso
			local oldpos = script.Parent.Torso.Position
			local NPCroot = part.Parent.Torso
			script.Parent.Torso.CFrame = CFrame.new(script.Parent.PrimaryPart.Position,NPCroot.Position)
			attackdeb = true
			CharRoot.Position = oldpos
		    part.Parent.Humanoid:TakeDamage(script.Configuration.DMG.Value)
			wait(script.Configuration.FireRate.Value)
			attackdeb = false
			else
			wait(0.2)
			end
		end
    end
end

Yea that looks like the issue, there’s no wait for when the enemy is still alive, only if when th enemy is dead, you have to put a wait somewhere i nthe while loop, probably if when the if statement is met

1 Like

Sometimes it doesn’t even shoot and it crashes :confused:

What value does the FireRate value in the Configuration contains?

Oh and you wanted the code that places the tower too?

That’s not required since it’s an issue with shooting

Yes it’s probably the absence of the delay in the while, usually it give you an error saying exausted…

It contains a value of 1 so I don’t know. It worked yesterday now it’s just broken.

Did you change/add anything from yesterday till today?

Nope. Only the placing system.

Is this something to do with it?

image

That’s unrelated as that is a plugin, What did you add from yesterday to today in your placing system?

Making it turn red when you couldn’t place it. As I said. It worked yesterday

Try this perhaps instead?

local function dmg(part)
	if not attackdeb then
		while enemyinzone do
			if part.Parent.Humanoid.Health > 0 then
				script.Parent.HumanoidRootPart.pistol_shoot:Play()
				local CharRoot = script.Parent.Torso
				local oldpos = script.Parent.Torso.Position
				local NPCroot = part.Parent.Torso
				script.Parent.Torso.CFrame = CFrame.new(script.Parent.PrimaryPart.Position,NPCroot.Position)
				attackdeb = true
				CharRoot.Position = oldpos
				part.Parent.Humanoid:TakeDamage(script.Configuration.DMG.Value)
				wait(script.Configuration.FireRate.Value)
				attackdeb = false
			end
			wait(0.2)
		end
    end
end

I’ll give it a try real quick.

Nope it just makes it crash faster.