Hello, good morning, afternoon and evening. I have a problem and I don’t know how to solve it. Can someone solve it and give me feedback? I am a newbie who is learning to program
local modelo = script.Parent
local placa = modelo.Placa
local Bola = modelo.Bola
local puerta = modelo.Puerta
local debounce = true
local nuevaBola = nil
local debris = game:GetService("Debris")
function tocar(hit)
------------Error ↷ ----------
local hum = hit.Parent:FindFirstChildOfClass("Humanoid") -- 🡨 Error
if not hum then return end
if debounce then return end
debounce = false
puerta.CanCollide = false
puerta.Transparency = 1
debris:AddItem(Bola, 8)
end
function trampa()
nuevaBola = Bola:Clone()
nuevaBola.Anchored = false
nuevaBola.Transparency = 0
nuevaBola.Parent = modelo
nuevaBola.CanCollide = true
puerta.Transparency = 0
puerta.CanCollide = true
nuevaBola.Destroying:Connect(trampa)
debounce = true
end
placa.Touched:Connect(function(hit)
tocar()
end)
trampa()
It seems like you have forgotten to add “hit” into tocar(). Should be like this: tocar(hit)
Oh and by the way, in this line here there could be a problem later on:
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
If for example your leg is the “hit” here everything is fine. But if a part inside an accessory gets hit then it wont work because the parent wont be the humanoid.
If you’ve already fixed the connection using placa.Touched:Connect(tocar), then the issue is how the debounce is set up.
Right now, you’re setting debounce = true at the start of the script, which causes the function tocar to immediately return when triggered because it’s checking if debounce is already true.
To fix this, you should define debounce = false at the start instead, so the first touch can actually go through.
Better Solution If Debounce Has To Be True When Defined
Also, in the trampa function, you’re setting debounce = true again, so instead of changing the debounce at the start of the script, you can just change it inside of the trampa function.
I had made a mistake with early return, I forgot to put not in dobunce, but now the new problem is that I can’t clone Part:Clone
local modelo = script.Parent
local placa = modelo.Placa
local Bola = modelo.Bola
local puerta = modelo.Puerta
local debounce = true
local nuevaBola = nil
local debris = game:GetService("Debris")
function OnTouch(hit)
local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
print("1")
if not hum then return end
if not debounce then return end
debounce = false
puerta.CanCollide = false
puerta.Transparency = 1
debris:AddItem(Bola, 5)
print("2")
end
function trampa()
print("clone")
nuevaBola = Bola:Clone()
nuevaBola.Anchored = false
nuevaBola.Transparency = 0
nuevaBola.Parent = modelo
nuevaBola.CanCollide = true
puerta.Transparency = 0
puerta.CanCollide = true
nuevaBola.Destroying:Connect(trampa)
debounce = true
print("3")
end
placa.Touched:Connect(OnTouch)
trampa()