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

Why don't my wanted level scripts work? What have I done wrong in my scripts?

Hi there. So today I tried to make a wanted level script where if you shoot a cop you become wanted. I decided to use a value for the wanted level and a script that makes the value go up.

if script.Parent.Humanoid.Health == 0 then
	workspace.WantedStars.Value = workspace.WantedStars.Value + 1
end

Then inside the value, I added a script that detects if the value went up. If it did, then it makes the cops hostile.

if script.Parent.Value == 1 then
	workspace.Police1["NPC AI"].Disabled = false
	workspace.Police2["NPC AI"].Disabled = false
	workspace.Police4["NPC AI"].Disabled = false
	workspace.Police3["NPC AI"].Disabled = false
	workspace.Police5["NPC AI"].Disabled = false
	workspace.Police6["NPC AI"].Disabled = false
	workspace.Police7["NPC AI"].Disabled = false
	workspace.Police8["NPC AI"].Disabled = false
end

2 comments

0

I figured out the problem.. sort of. This is just a guess but I think the scripts that are supposed to be enabled break and the character does not shoot me even after killing them

0

Well I think the problem is with the script that gives you a wanted level when you kill the npc. Whenever I kill them, the value doesn't go up!

1 answer

Those scripts will not work like that. I am assuming this are whole scripts, right? They will only check for value once at the start of the game, and never run again.

To fix this, the easiest way would be to encapsulate them in infinite loops.

while true do
	if script.Parent.Humanoid.Health == 0 then
	    workspace.WantedStars.Value = workspace.WantedStars.Value + 1
        break -- I forgot the break
	end
	wait(1) --check every second
end

Other script:

while true do
	if script.Parent.Value == 1 then
	    workspace.Police1["NPC AI"].Disabled = false
	    workspace.Police2["NPC AI"].Disabled = false
	    workspace.Police4["NPC AI"].Disabled = false
	    workspace.Police3["NPC AI"].Disabled = false
	    workspace.Police5["NPC AI"].Disabled = false
	    workspace.Police6["NPC AI"].Disabled = false
	    workspace.Police7["NPC AI"].Disabled = false
	    workspace.Police8["NPC AI"].Disabled = false
	end
	wait(1) -- check every second
end

Proper way to do this however would be to add an event listener. But for beginners, this method is recommended.

2 comments

0

This method does not work properly. The wanted level keeps adding up when the bot dies.

0

Answer edited, should work now

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