Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script clone a new object twice?

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 answer

✓ Accepted answer

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.

1 comment

0

Yes it worked! Thanks so much.

This discussion is preserved as it was. New answers, comments, and votes are closed.