Script not working

Hello everyone.

I’m making a game like Five Nights at Freddy’s in Roblox. Everything is done except the main menu and GUI. The problem is that the enemy AI isn’t turning on and off. I tried disabling the script and using values but nothing worked. And the EnemyAI scripts are loops if that helps.

This is how the game would work:

  • Joining the game
  • Clicking a start button
  • Cutscene plays
  • AI turning on (PROBLEM)
  • When you die the game takes you to the main menu
  • AI turning off (PROBLEM)
  • Everything resets
  • Clicking a start button (Playing again)

This is the script for one of the enemies:

while workspace.Values.Start.Value == true do -- I don't know what to do here

	if script.Parent.Position.Z == -25 then
		
		workspace.Values.ClockJumpscare.Value = true -- Death

	else
	-- Enemy Movement
        script.Parent.Parent.Parent.NeonPart.Transparency = 1
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.8
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.8
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.4
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.2
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0
		wait(0.1)
		script.Parent.Position += Vector3.new(0, 0, -2.5)
		wait(0.375)
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.2
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.4
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.6
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 0.8
		wait()
		script.Parent.Parent.Parent.NeonPart.Transparency = 1

	end
end

Thanks for reading.

1 Like

Could you put a boolean value in the NPC that you can check to see if it’s AI is on?

call it by doing a simple if NPC.AI_IS_ON.Value == true then
– Do Code
else
– Don’t do code
end

This isn’t a very Efficient way to Create a Pulse Animation, try TweenService

local Obj = script.Parent.Parent.Parent.NeonPart

local Tween = TweenService:Create(Obj, TweenInfo.new(.3), {Transparency = 0})
Tween:Play()
Tween.Completed:Wait()

script.Parent.Position += Vector3.new(0, 0, -2.5)

Tween = TweenService:Create(Obj, TweenInfo.new(.3), {Transparency = 1})
Tween:Play()
Tween.Completed:Wait()

1 Like

Something about your system confuses me, are you checking the GUI button press AND turning on the AI on the client? Or have you divided them into different sided scripts?

If you already set up the different sides and need them to xommunicate, you can use RemoteEvents

Still doesn’t work (another enemy script)

while wait(1) do
		
if workspace.Values.Start.Value == true then

	if script.Parent.Transparency == 0 then
		
		workspace.Values.CameraJumpscare.Value = true
		
	else
		
		script.Parent.Transparency = script.Parent.Transparency - 0.05

	end
	end
end

I set the RunContext to client and disabled the script and everything worked.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.