**1. What do you want to achieve?
I want to implement a function to the puzzle system that when the cube taken by any user and when it dies, the cube returns to its position.
**2. What is the issue?
my chicken brain still doesn’t understand this programming field, I’m still learning but I don’t really know how to do this function.
- **What solutions have you tried so far?
I tried to use a localscript but it gave me many errors, besides the system is a literal script visible to all also tried with a remote event, in the end just leave it as a script, I understand that the function is used died.funcion but still do not know how to do it and if you die with a certain cube that has in the backpack or in the hand is the one that returns to its original position or clone. less context here I pass the script, I appreciate the help much
If I have not explained well, what I want to achieve is a system like in the game of rainbow friends to take some cubes and take them to a certain point but if the user dies, the cube returns to its position.
local toched = script.Parent
local db = true
local players = game:GetService("Players")
function completo()
if toched.Toucheds.red.Transparency == 0 then
if toched.Toucheds.blue.Transparency == 0 then
if toched.Toucheds.Green.Transparency == 0 then
if toched.Toucheds.Yellow.Transparency == 0 then
toched.Part.Transparency = 1
end
end
end
end
end
function removeTool(Name)
for i, value in pairs( players:GetChildren()) do
local character = value.Character:FindFirstChild(Name)
local backpack = value.Backpack:FindFirstChild(Name)
if character then
character:destroy()
end
if backpack then
backpack:destroy()
end
end
end
toched.Hitbox.Part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild(toched.Toucheds.red.Value.Value) then
db = false
toched.Toucheds.red.Transparency = 0
removeTool("Tool4")
completo()
wait(0.5)
db = true
end
end)
toched.Hitbox.Part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild(toched.Toucheds.blue.Value.Value) then
db = false
toched.Toucheds.blue.Transparency = 0
removeTool("Tool3")
completo()
wait(0.5)
db = true
end
end)
toched.Hitbox.Part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild(toched.Toucheds.Green.Value.Value) then
db = false
toched.Toucheds.Green.Transparency = 0
removeTool("Tool2")
completo()
wait(0.5)
db = true
end
end)
toched.Hitbox.Part.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild(toched.Toucheds.Yellow.Value.Value) then
db = false
toched.Toucheds.Yellow.Transparency = 0
removeTool("Tool1")
completo()
wait(0.5)
db = true
end
end)


