Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

game crashes after running these two scripts?

i am trying to make so that when you knock down a street light pole it will sound but if you were to touch it a tiny bit it crashes

script 1

local NumberToEndAt = 0

local numberboi = script.Parent.TouchesTillKnockOver.Value

--numberboi.math.clamp(0,1,340)
script.Parent.TouchesTillKnockOver.Changed:Connect(function()
	if script.Parent.TouchesTillKnockOver.Value <= 0 then
		script.Parent.TouchesTillKnockOver.Value = 0
	end

	if script.Parent.TouchesTillKnockOver.Value == 0 then
		script.Parent.base.Anchored = false
		script.Parent.Union.Anchored = false
		script.Parent.Union1.Anchored = false
		script.Parent.Part.Anchored = false
		script.Parent.light.Anchored = false
		script.Parent.light.Material = Enum.Material.Glass
		script.Parent.light.SpotLight.Enabled = false
		script.Parent.UnAnchored.Value = true
		script.Parent.streetlightsound:Play()
		print("touched and unanchored")
		wait(0.1)
		script.Parent.UnAnchored.Value = true
		wait(0.1)
		script.Parent.UnAnchored.Value = false
		script.Parent.streetlightsound:Pause()
		repeat 
			script.Parent.streetlightsound:Pause()
		until  script.StopScrpt.Value == true
	end
end)

script 2

script.Parent.Union.Touched:Connect(function()
	
	script.Parent.TouchesTillKnockOver.Value = script.Parent.TouchesTillKnockOver.Value - 1
	
	
	if script.Parent.UnAnchored.Value == true then
		print("waiting for 10")
		wait(10)
		
		script.Parent.base.Anchored = true
		script.Parent.light.SpotLight.Enabled = true
		script.Parent.Union.Anchored = true
		script.Parent.Union1.Anchored = true
		script.Parent.Part.Anchored = true
		script.Parent.light.Anchored = true
		script.Parent.base.Position = Vector3.new(-182.745, 1, 8.193)
		script.Parent.base.Orientation = Vector3.new(0, 90, 0)
		script.Parent.light.Material = Enum.Material.Neon
		script.Parent.Union.Position = Vector3.new(-182.745, 6.5, 8.197)
		script.Parent.Union.Orientation = Vector3.new(0, 90, 90)
		script.Parent.Union1.Position = Vector3.new(-182.745, 12.6, 8.193)
		script.Parent.Union1.Orientation = Vector3.new(0, 90, 90)
		script.Parent.Part.Position = Vector3.new(-182.745, 13.35, 6.893)
		script.Parent.Part.Orientation = Vector3.new(-90, -180, 0)
		script.Parent.light.Position = Vector3.new(-182.745, 13.05, 6.893)
		script.Parent.light.Orientation = Vector3.new(-90, -180, 0)
		print("back to how it started")
		script.Parent.SoundScript.StopScrpt.Value = true
	end
end)

if script.Parent.TouchesTillKnockOver.Value == 0 then
	
end
	--game.Players:GetPlayerFromCharacter (hit.Parent)
	--script.parent.Part

1 comment

1

Script one, lines 27-29 are crashing the game. Just add wait() into the loop and that should fix it.

1 answer

In lines 27 through 29 on the first script, you are using a repeat until loop without a pause or a waiting signal, which will result in the studio crashing. You can add something simple there like wait(). Hope this helps

This discussion is preserved as it was. New answers, comments, and votes are closed.