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

I made a script for a enemy AI. but i have gotten a few errors...?

here is my script:

local Zombie = game.ReplicatedStorage:FindFirstChild("Zombie")

local Attack = Zombie.AiScript local Humanoid = Zombie.Humanoid

local Player = game.Players local Players = Player.LocalPlayer

local Clicker = Zombie.ClickDetector

local function Attack() if Humanoid.Touched:Connect() then Player.Humanoid.Health = 0 elseif Player.Humanoid.Health == 100 end end

local function Attack()

local function Clicked(function() if Clicker.MouseButton1Down:Connect() Zombie.Humanoid.Health = 0 elseif Zombie.Humanoid.Health = 100 end)

local function Clicked()

it says: 14:13:07.961 - Workspace.Zombie.AiScript:18: Expected 'then' when parsing if statement, got 'end'

...Pls Help!!!

1 answer

✓ Accepted answer

Here I Corrected Your Code. Comment If It Doesn't Work. I Edited It You Did Not Run The Function When The Person Clicks.

local Zombie = game.ReplicatedStorage:FindFirstChild("Zombie")

local Attack = Zombie.AiScript

local Humanoid = Zombie.Humanoid

local Player = game.Players

local Players = Player.LocalPlayer.Character

local Clicker = Zombie.ClickDetector

local function Attack()
	if Humanoid.Touched:Connect() then
		Player.Humanoid.Health = 0
	else
		if Player.Humanoid.Health == 100 then
			--Your Other Function Here
		end
	end
end

local function Clicked()
	if Clicker.MouseButton1Down:Connect() then
		Zombie.Humanoid.Health = 0 
	else
		if Zombie.Humanoid.Health == 100 then
			--Your Other Code Piece Here I Guess
		end
	end
end

8 comments

0

Alright. So it seems to work, until I tried to click the zombie to kill it...It didn't do anything...

0

Oh

0

yeah... :/

0

I'm thinking os using a break joint function, but I'm not too sure how to use it...

0
0

Aight! Thank you very much for your help!

0

Your Welcome You Can Contact Me At Lua#8082 Any Time On Discord If You Need Help For Future Scripts.

0

ok :)

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