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

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

Asked by 4 years ago

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)

0
I don't understand why you are putting connection = an event. deeskaalstickman649 475 — 4y
0
so that he can disconnect it in the end ofc zadobyte 692 — 4y
0
accept deeskaal's answer if it helped please zadobyte 692 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

You're writing

local function

which creates a new function. To set a variable equal to a function, write:

variable name = function(paramaters)

.

0
ohhh mandibleknox 6 — 4y
Ad

Answer this question