local partsSpawned = game.Workspace.partsSpawned
local repstorage = game:GetService("ReplicatedStorage")
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild("spawner")
local button = script.Parent
button.MouseButton1Down:Connect(function()
local new = spawnpart:Clone()
new.Parent = partsSpawned
new.CFrame = spawner.CFrame
end)
It does not want to put another spawned part in the old part
How can I make it if anyone clicks on the button and click the button again spawns another part in the old part
Can someone help me?
`
local partsSpawned = game.Workspace.partsSpawned
local repstorage = game:GetService(“ReplicatedStorage”)
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild(“spawner”)
local button = script.Parent
local Cf
button.MouseButton1Down:Connect(function()
local new = spawnpart:Clone()
new.Parent = partsSpawned
if Cf then
Cf = Cf * CFrame.new(0,1,0) ----- u can change that hovewer you want
else
Cf = spawner.CFrame
end
new.CFrame = Cf
Since you want the new parts to get below the old ones its a bit tricky but a simple loop to move all the old ones up should do it.
local partsSpawned = workspace:WaitForChild("partsSpawned")
local repstorage = game:GetService("ReplicatedStorage")
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild("spawner")
local button = script.Parent
local partY = spawnpart.Size.Y
local function MovePartsUp()
for i,v in partsSpawned:GetChildren() do
v.CFrame *= CFrame.new(0,partY,0)
end
end
button.MouseButton1Down:Connect(function()
MovePartsUp()
local new = spawnpart:Clone()
new.Parent = partsSpawned
new.CFrame = spawner.CFrame
end)
then use a counter and multiply it by the Y size of the part everytime :
local partsSpawned = workspace:WaitForChild("partsSpawned")
local repstorage = game:GetService("ReplicatedStorage")
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild("spawner")
local button = script.Parent
local partY = spawnpart.Size.Y
local counter = 0
button.MouseButton1Down:Connect(function()
local new = spawnpart:Clone()
new.Parent = partsSpawned
new.CFrame = spawner.CFrame * CFrame.new(0,partY * counter,0)
counter += 1
end)
One question more:
Can I put this in a server script (in ServerScriptService):
game.Players.PlayerAdded:Connect(function(plr)
while wait(1) do
if plr.Character then
local partsSpawned = workspace:WaitForChild("partsSpawned")
local repstorage = game:GetService("ReplicatedStorage")
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild("spawner")
local button = script.Parent
local partY = spawnpart.Size.Y
local counter = 0
local new = spawnpart:Clone()
new.Parent = partsSpawned
new.CFrame = spawner.CFrame * CFrame.new(0,partY * counter,0)
counter += 1
end
end
end)
you can but i don’t understand the point of it. You’re trying to add the part from the server so every player will see it, but at the same time you’re doing it for all the players.
Also do you want a part to be added every second?
Yeah, I want to make a game like +1 block every second or get richer every second
and I needed a script that spawn part every second or when anyone click on the button
game.Players.PlayerAdded:Connect(function(plr)
while wait(1) do
if plr.Character then
local partsSpawned = workspace:WaitForChild("partsSpawned")
local repstorage = game:GetService("ReplicatedStorage")
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild("spawner")
local button = script.Parent
local partY = spawnpart.Size.Y
local counter = 0
local new = spawnpart:Clone()
new.Parent = partsSpawned
new.CFrame = spawner.CFrame * CFrame.new(0,partY * counter,0)
counter += 1
end
end
end)
First of all if you put this in ServerScriptService, there is no such thing button = script.Parent remove that, also … you know what i’ll just fix the script here:
local partsSpawned = workspace:WaitForChild("partsSpawned")
local repstorage = game:GetService("ReplicatedStorage")
local spawnpart = repstorage.part
local spawner = game.Workspace:WaitForChild("spawner")
local partY = spawnpart.Size.Y
game.Players.PlayerAdded:Connect(function(plr)
local counter = 0
while task.wait(1) do
if plr.Character then
local new = spawnpart:Clone()
new.Parent = partsSpawned
new.CFrame = spawner.CFrame * CFrame.new(0,partY * counter,0)
counter += 1
end
end
end)