This is a script for my game. It’s a local script since I want the parts to generate on client. Basically, It used to work all good unless now. You have to stop the generation and start it again when changing a property of a part. Why is that? I don’t want to stop and start the generation for changes to be detected…
Note: I parent my parts to a folder in workspace.
Please ignore the variables and other stuff, refer to the heart beat function and the if statements…
--// Main Variables and Services
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local partsUpdateText = script.Parent.UpdateText
local ClickSound = ReplicatedStorage.GameSounds.ClickSound
local PartsGenerateArea = workspace.Map.PartsGenerateArea:WaitForChild("Main")
local Remotes = ReplicatedStorage.Remotes
local TotalParts = Remotes.TotalParts
local partsEvent = false
--// Variables for buttons
local stopButton = script.Parent.StopGeneration
local generateButton = script.Parent.GenerateButton
local fireEffectButton = script.Parent.PartSettings.fireButton
local smokeEffectButton = script.Parent.PartSettings.smokeButton
local woodButton = script.Parent.PartSettings.Wood
local woodPlanksButton = script.Parent.PartSettings["Wood Planks"]
local SmoothPlasticButton = script.Parent.PartSettings["Smooth Plastic"]
local iceButton = script.Parent.PartSettings.Ice
local corrodedMetalButton = script.Parent.PartSettings["Corroded Metal"]
local plasticButton = script.Parent.PartSettings.Plastic
local FireEffector = ReplicatedStorage.PartEffects.FireEffect
local diamondPlateButton = script.Parent.PartSettings["Diamond Plate"]
local forceFieldButton = script.Parent.PartSettings["Force Field"]
local SmokeEffector = ReplicatedStorage.PartEffects.SmokeEffect
local sphereButton = script.Parent.PartSettings.Sphere
local blocksButton = script.Parent.PartSettings.Block
local cylinderButton = script.Parent.PartSettings.Cylinder
local PartConclusionFrame = script.Parent.PartSettings.PartConclusion
-- Variables for effects
local FireEffect = false
local SmokeEffect = false
-- Variables for materials
local wood = false
local woodPlanks = false
local corrodedMetal = false
local plastic = false
local smoothPlastic = false
local ice = false
local diamondPlate = false
local forcefield = false
local explosion = false
local cylinder = false
local block = false
local sphere = false
--// Variables for parts generation
local partsGenerated = 0
RunService.Heartbeat:Connect(function()
if partsEvent then
local parts = Instance.new("Part")
TotalParts:FireServer()
partsGenerated = partsGenerated + 1
partsUpdateText.Text = partsGenerated
parts.CFrame = PartsGenerateArea.CFrame
parts.Size = Vector3.new(5,5,5)
parts.Transparency = .5
parts.Material = Enum.Material.SmoothPlastic
parts.BrickColor = BrickColor.new("Pastel Blue")
parts.Parent = workspace.PartsStorage
--// Conditions for part shapes
if sphere then
parts.Shape = Enum.PartType.Ball
end
if cylinder then
parts.Shape = Enum.PartType.Cylinder
end
if block then
parts.Shape = Enum.PartType.Block
end
--// Condition for materials
if wood then
parts.Material = Enum.Material.Wood
end
if woodPlanks then
parts.Material = Enum.Material.WoodPlanks
end
if corrodedMetal then
parts.Material = Enum.Material.CorrodedMetal
end
if plastic then
parts.Material = Enum.Material.Plastic
end
if smoothPlastic then
parts.Material = Enum.Material.SmoothPlastic
end
if ice then
parts.Material = Enum.Material.Ice
end
if forcefield then
parts.Material = Enum.Material.ForceField
end
if diamondPlate then
parts.Material = Enum.Material.DiamondPlate
end
if FireEffect then
FireEffector:Clone()
FireEffector = parts
end
if SmokeEffect then
SmokeEffector:Clone()
SmokeEffector.Parent = parts
end
end
end)
local debounce = true
local debounce2 = true
--// MouseButton1Click functions for text buttons
sphereButton.MouseButton1Click:Connect(function()
ClickSound:Play()
sphere = true
block = false
cylinder = false
PartConclusionFrame["Shape Selected"].Text = "Shape Selected: Sphere"
end)
cylinderButton.MouseButton1Click:Connect(function()
ClickSound:Play()
cylinder = true
sphere = false
block = false
PartConclusionFrame["Shape Selected"].Text = "Shape Selected: Cylinder"
end)
blocksButton.MouseButton1Click:Connect(function()
ClickSound:Play()
block = true
sphere = false
cylinder = false
script.Parent.PartSettings.PartConclusion["Shape Selected"].Text = "Shape Selected: Block"
end)
diamondPlateButton.MouseButton1Click:Connect(function()
ClickSound:Play()
diamond = true
wood = false
corrodedMetal = false
woodPlanks = false
ice = false
smoothPlastic = false
plastic = false
forcefield = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Diamond Plate"
end)
forceFieldButton.MouseButton1Click:Connect(function()
ClickSound:Play()
forcefield = true
diamond = false
wood = false
corrodedMetal = false
woodPlanks = false
ice = false
smoothPlastic = false
plastic = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Force Field"
end)
woodButton.MouseButton1Click:Connect(function()
ClickSound:Play()
wood = true
forcefield = false
diamond = false
corrodedMetal = false
woodPlanks = false
ice = false
smoothPlastic = false
plastic = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Wood"
end)
woodPlanksButton.MouseButton1Click:Connect(function()
ClickSound:Play()
woodPlanks = true
forcefield = false
diamond = false
wood = false
ice = false
corrodedMetal = false
smoothPlastic = false
plastic = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Wooden Planks"
end)
corrodedMetalButton.MouseButton1Click:Connect(function()
ClickSound:Play()
corrodedMetal = true
forcefield = false
diamond = false
wood = false
ice = false
smoothPlastic = false
plastic = false
woodPlanks = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Corroded Metal"
end)
plasticButton.MouseButton1Click:Connect(function()
ClickSound:Play()
plastic = true
forcefield = false
diamond = false
smoothPlastic = false
ice = false
corrodedMetal = false
wood = false
woodPlanks = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Plastic"
end)
SmoothPlasticButton.MouseButton1Click:Connect(function()
ClickSound:Play()
smoothPlastic = true
forcefield = false
diamond = false
plastic = false
wood = false
woodPlanks = false
ice = false
corrodedMetal = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Smooth Plastic"
end)
iceButton.MouseButton1Click:Connect(function()
ClickSound:Play()
ice = true
forcefield = false
diamond = false
plastic = false
wood = false
woodPlanks = false
corrodedMetal = false
smoothPlastic = false
PartConclusionFrame["Material Selected"].Text = "Material Selected: Ice"
end)
fireEffectButton.MouseButton1Click:Connect(function()
ClickSound:Play()
FireEffect = true
SmokeEffect = false
PartConclusionFrame["Effects Selected"].Text = "Effects Selected: Fire"
end)
smokeEffectButton.MouseButton1Click:Connect(function()
ClickSound:Play()
SmokeEffect = true
FireEffect = false
PartConclusionFrame["Effects Selected"].Text = "Effects Selected: Smoke"
end)
generateButton.MouseButton1Click:Connect(function()
ClickSound:Play()
if not partsEvent then
partsEvent = true
if debounce then
debounce = false
debounce2 = true
stopButton.Visible = true
generateButton.Visible = false
end
end
if debounce then
debounce = false
debounce2 = true
partsEvent = false
stopButton.Visible = true
generateButton.Visible = false
end
end)
stopButton.MouseButton1Click:Connect(function()
ClickSound:Play()
partsEvent = false
stopButton.Visible = false
generateButton.Visible = true
generateButton.Text = "Start Part Generation"
if debounce2 then
debounce2 = false
debounce = true
workspace.PartsStorage:Destroy()
partsGenerated = 0
partsUpdateText.Text = partsGenerated
local partsStorage = Instance.new("Folder")
partsStorage.Name = "PartsStorage"
partsStorage.Parent = workspace
partsUpdateText.Text = "Parts Generated: "..partsGenerated
end
end)
Note: If you stop and re start the part generation, property changes when changing them through part settings…