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

Is it possible to use 'if () then'?

Is it possible to use an if statement on a function, e.g:

local touched = false
script.Parent.Touched:Connect(function(hit)
	warn("1")
	if touched == false then
		warn("2")
	touched = true
	while hit.Parent.Humanoid.Health >0 and touched == true do
		warn("3")
		hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
		wait()
		if script.Parent.TouchEnded then -- is this possible?
			warn("4")
			touched = false
			break
			
			end
			
			
		end
		end
	
end)

Thanks!

5 comments

0

I'm not sure but I think it's not possible because it's an event. It's suppose to be script.Parent.TouchEnded:Connect(function() end).

0

No you can't do that, you can do TouchEnded:Wait() and it will yeild the script until the event occures

0

Your question and you script doesn't really match, you can use a function in an if statement. But you can't use an Event, which is what you're doing in your script

0

ok thx

0

i think you can use anything on if statements im pretty sure as along they dont refer to nil or false. Even you don't need to call the function you can still compare it since it's not nil or false

1 answer

I don't think it's possible but I might be wrong. Because your referencing a function with an if statement doing this:

if hit.Parent:FindFirstChild( "Humanoid") then 
warn (4)
touched = false

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