Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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)

3 comments

0

I don't understand why you are putting connection = an event.

0

so that he can disconnect it in the end ofc

0

accept deeskaal's answer if it helped please

1 answer

✓ Accepted answer

You're writing

local function

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

variable name = function(paramaters)

.

1 comment

0

ohhh

This discussion is preserved as it was. New answers, comments, and votes are closed.