Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I am unsure of how this global variable doesn't work? [closed]

Asked by 4 years ago

This question already has an answer here:

I am unsure of how this global variable doesn't work?

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)

Marked as Duplicate by raid6n, zadobyte, and pwx

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?