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

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

Asked by 3 years ago
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'

0
error is located at the RArm event ABCTrainerDude 12 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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!

0
What?? JesseSong 3916 — 3y
0
local events are :connect and :wait. TheEagle722 170 — 3y
0
oh ABCTrainerDude 12 — 3y
Ad
Log in to vote
0
Answered by
Borrahh 265 Moderation Voter
3 years ago

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

Answer this question