0

# Why does my script clone a new object twice?

Asked by 7 months ago

This script is inside a block.

When I click on the block with a tool it fires to server and makes the block start getting more transparent and then it's transparency ends at 1 and turns CanCollide off.

This script is inside the block and detects when the block changes transparency, and when it's at 1 it clones a bone from replicated storage to the block... But it clones twice and idk why

boneType = script.Parent.Name
debounce = false

script.Parent.Changed:Connect(function()
if not debounce then
debounce = true
if script.Parent.Transparency == 1 then

local newBone = game.ReplicatedStorage[boneType]:Clone()
newBone.Position = script.Parent.Position
newBone.Anchored = false
newBone.Parent = game.Workspace.Bones

print("clone")

end

debounce = false
end
end)



1
memguy 141
7 months ago

You should use

:GetPropertyChangedSignal("Transparency")


so the script would look like this

boneType = script.Parent.Name
debounce = false

script.Parent:GetPropertyChangedSignal("Transparency"):Connect(function()
if not debounce then
debounce = true
if script.Parent.Transparency == 1 then

local newBone = game.ReplicatedStorage[boneType]:Clone()
newBone.Position = script.Parent.Position
newBone.Anchored = false
newBone.Parent = game.Workspace.Bones

print("clone")

end

debounce = false
end
end)


since you only want to call the function when transparency changes. Perhaps that is the problem beacuse other properties of the part can change.

0
Yes it worked! Thanks so much. ByteError 32 — 7mo