Hello, I have recently been creating a game with a system of mixing things by collision but this same system sometimes creates several new parts and for some reason they fade away and only leave one
Heres the code:
-- Require the cinnamorollmix module
local cinnamorollmix = require(game.ServerScriptService.cinnamorollmix)
-- Get the services needed
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local isMixing = false
-- Reference to the current part
local normalcinna = script.Parent
-- Function to handle the touch event
local function onTouch(otherPart)
if isMixing then return end -- Prevent multiple simultaneous mixes
for _, combo in ipairs(cinnamorollmix.mixCombinations) do
if otherPart.Name == combo.Part2 then
isMixing = true
local newPartName = combo.Result
local newPartTemplate = ReplicatedStorage:FindFirstChild("cinnamorollsmixes"):FindFirstChild(newPartName)
if newPartTemplate then
local newPart = newPartTemplate:Clone()
newPart.Position = normalcinna.Position
newPart.Parent = workspace
-- Remove DragDetector if it exists
local normalcinnaDragDetector = normalcinna:FindFirstChildOfClass("DragDetector")
if normalcinnaDragDetector then
normalcinnaDragDetector:Destroy()
end
local otherPartDragDetector = otherPart:FindFirstChildOfClass("DragDetector")
if otherPartDragDetector then
otherPartDragDetector:Destroy()
end
-- Add mixing effects
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local goal = {Transparency = 1}
local tweenNormalcinna = TweenService:Create(normalcinna, tweenInfo, goal)
local tweenOtherPart = TweenService:Create(otherPart, tweenInfo, goal)
tweenNormalcinna:Play()
tweenOtherPart:Play()
-- Wait for the fade animation to complete and destroy parts
tweenNormalcinna.Completed:Connect(function()
normalcinna:Destroy()
end)
tweenOtherPart.Completed:Connect(function()
otherPart:Destroy()
end)
-- Animation for the resulting part
local goalNewPart = {Transparency = 0}
local tweenNewPart = TweenService:Create(newPart, tweenInfo, goalNewPart)
tweenNewPart:Play()
-- Do not destroy the resulting part
tweenNewPart.Completed:Connect(function()
isMixing = false -- Reset the mixing condition here
end)
else
warn("Part not found in the cinnamorollsmixes folder")
isMixing = false
end
break
end
end
end
-- Configure the mix event for "normalcinna"
if normalcinna then
normalcinna.Touched:Connect(onTouch)
end
And a video: