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

Script not working, when humanoid touches another humanoid, suppose to damage?

So basically, LogiaNumber is like a activation, if it's 0 then you don't get the effect, but if it's 1 then you do get the effect, when other players try to touch you they get damage, but it's not working?

local player = game.Players.LocalPlayer
local Character = player.Character

if player.Leaderstats.LogiaNumber == 1 then
	if Character:FindFirstChild('Right Arm').Touched:connect(function(otherpart) 
	elseif Character:FindFirstChild('Left Arm').Touched:connect(function(otherpart) 
		
	end)
		then
		otherpart.Parent:FindFirstChild('Humanoid').Health = -3
	end
end

2 answers

local player = game.Players.LocalPlayer

local Character = player.Character

function hurt(otherpart)
	otherpart.Parent:FindFirstChild('Humanoid').Health = otherpart.Parent:FindFirstChild('Humanoid').Health - 3
end

if player.leaderstats.LogiaNumber == 1 then
Character:FindFirstChild('Right Arm').Touched:connect(function(otherpart) 
	hurt(otherpart)
end)
Character:FindFirstChild('Left Arm').Touched:connect(function(otherpart)
	hurt(otherpart)
end)

end

The code that was provided by 1234 caused the unexpected symbol error because you can't use an if statement on an connection. Remove the if, then, elseif, and the second to last end. Then add the ends to the functions. You also need to pass the otherpart variable through the hurt function otherwise it will give an nil variable error. And to remove 3 health from the otherpart you need to subtract the health by 3.

If this helped please rate up and set this as the answer.

Does your leaderboard work? Because I think leaderstats is meant to have a lower case "L"? I also cleared it up a bit...

local player = game.Players.LocalPlayer

local Character = player.Character

function hurt()
	otherpart.Parent:FindFirstChild('Humanoid').Health = -3
end

if player.leaderstats.LogiaNumber == 1 then
 if Character:FindFirstChild('Right Arm').Touched:connect(function(otherpart) then
	hurt()
  elseif Character:FindFirstChild('Left Arm').Touched:connect(function(otherpart)
	hurt()
end)

end

end

1 comment

0

Seems more corrected now, but there's another error now and it says "unexpected symbol near "then"

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