I am a little confused on why this doesn't work, i'm somewhat of a beginner but i do have some understanding of some complex things. I created a global variable for "clone" and assigned it within an if statement which is also in a while true do loop. I thought that when i assigned this clone a value i would be able to access it outside(the scope) and create a touched event . I also did put the event with the scope also but nothing came up within the output. Here is the code
local part = game.Workspace.Healer
local connection
local Debounced = false
local clone
local touched
-- Spawning partHealer
while true do
wait(2)
if Debounced == false then
wait(5)
clone = part:Clone()
clone.Name = "Clone"
clone.Parent = game.Workspace
Debounced = true
end
-- touched function for clone --
local function touched(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid and Debounced == true then
print("Hello World")
wait()
connection:Disconnect()
clone:Destroy()
end
end
end
connection = clone.Touched:Connect(touched)
