Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to clone object but constantly keep changing it's properties?

Asked by
R0jym 47
2 years ago

Hello there, I have a script here where it's supposed to clone itself BUT continously update it's properties everytime it is cloned, like in this script where it's numbers add everytime it is cloned along with it's position, however I do not know on how to approach this and it does not seem to work, how do I remedy this?

1local RS = game:GetService('ReplicatedStorage')
2local AdditionEvent = RS:WaitForChild('AdditionEvent')
3local Block = game.Workspace.Block
4 
5AdditionEvent.OnServerEvent:Connect(function(event)
6    Block:Clone()
7    Block.CFrame = Block.CFrame * (0,4,0)
8        Block.SurfaceGui.TextLabel.Text +=1
9end)
0
You are trying to set the CFrame of the block that is in the workspace, and not the cloned one. ROMAHKAO 35 — 2y

1 answer

Log in to vote
1
Answered by
Puppynniko 1059 Moderation Voter
2 years ago
Edited 2 years ago

You would want to put the Cloned Block into a Variable as i think you cant access the Cloned block if you dont also you forgot to place the cloned block in workspace and you also need to have a currentNumber or it would add Block.SurfaceGui.TextLabel.Text as 0 to 1 then it would add 1 to 0 again after it cloned again like this

01local RS = game:GetService('ReplicatedStorage').Remotes
02local AdditionEvent = RS:WaitForChild('AdditionEvent')
03local Block = game.Workspace.Block
04local CurrentNumber = 1
05local CurrentCFrame = Block.CFrame
06AdditionEvent.OnServerEvent:Connect(function(event)
07    local ClonedBlock = Block:Clone()
08    ClonedBlock.Parent = workspace
09    CurrentCFrame = CurrentCFrame * CFrame.new(0,4,0)
10    ClonedBlock.CFrame = CurrentCFrame
11    CurrentNumber = CurrentNumber + 1
12    ClonedBlock.SurfaceGui.TextLabel.Text = CurrentNumber
13end)
Ad

Answer this question