Ad
Log in to vote
1

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

Asked by
R0jym 47
5 months 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?

local RS = game:GetService('ReplicatedStorage')
local AdditionEvent = RS:WaitForChild('AdditionEvent')
local Block = game.Workspace.Block

AdditionEvent.OnServerEvent:Connect(function(event)
    Block:Clone()
    Block.CFrame = Block.CFrame * (0,4,0)
        Block.SurfaceGui.TextLabel.Text +=1
end)
0
You are trying to set the CFrame of the block that is in the workspace, and not the cloned one. ROMAHKAO 35 — 5mo

1 answer

Log in to vote
1
Answered by 5 months ago
Edited 5 months 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

local RS = game:GetService('ReplicatedStorage').Remotes
local AdditionEvent = RS:WaitForChild('AdditionEvent')
local Block = game.Workspace.Block
local CurrentNumber = 1
local CurrentCFrame = Block.CFrame
AdditionEvent.OnServerEvent:Connect(function(event)
    local ClonedBlock = Block:Clone()
    ClonedBlock.Parent = workspace
    CurrentCFrame = CurrentCFrame * CFrame.new(0,4,0)
    ClonedBlock.CFrame = CurrentCFrame
    CurrentNumber = CurrentNumber + 1
    ClonedBlock.SurfaceGui.TextLabel.Text = CurrentNumber
end)
Ad

Answer this question