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

So when I do a touched event, it errors out, why?

if meleebool == true then

	if RArm.Touched:Connect(function(hit) then
		if hit.Parent.Humanoid then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
		end
	end)

	if LArm.Touched:Connect(function(hit) then
		if hit.Parent.Humanoid then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
		end
	end)

	if weaponinhand.Touched:Connect(function(hit) then
		if hit.Parent.Humanoid then
			hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
		end
	end)

end

error: Expected identifier when parsing expression, got 'then'

1 comment

0

error is located at the RArm event

2 answers

✓ Accepted answer

local events are NEVER can be in if.. then. try just removing if's and then's.

if meleebool == true then

    RArm.Touched:Connect(function(hit) 
        if hit.Parent.Humanoid then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
        end end)

    LArm.Touched:Connect(function(hit) 
        if hit.Parent.Humanoid then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
        end end)

    weaponinhand.Touched:Connect(function(hit) 
        if hit.Parent.Humanoid then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
        end end)

end

I hope i was able to help! good day!

3 comments

0

What??

0

local events are :connect and :wait.

0

oh

Basically with Events, You don't need to use an IF Statement.

if meleebool == true then

     RArm.Touched:Connect(function(hit)
         hit.Parent.Humanoid then
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
        end
    end)

     LArm.Touched:Connect(function(hit) then
        hit.Parent.Humanoid 
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
        end
    end)

     weaponinhand.Touched:Connect(function(hit) 
         hit.Parent.Humanoid 
            hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -12
        end
    end)

end

The Event is going to fire when the RArm is going to be touched, so there is no need to check if it got touched or not

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