Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 days 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 14 — 2d

2 answers

Log in to vote
0
Answered by 2 days ago
Edited 2 days 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 3389 — 2d
0
local events are :connect and :wait. TheEagle722 99 — 2d
0
oh ABCTrainerDude 14 — 11h
Ad
Log in to vote
0
Answered by
EEnergy8 225 Moderation Voter
1 day 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