Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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
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 MrMonthh 11 — 3y
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! MrMonthh 11 — 3y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
3 years ago
Edited 3 years ago

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.

0
This method does not work properly. The wanted level keeps adding up when the bot dies. MrMonthh 11 — 3y
0
Answer edited, should work now sleazel 1287 — 3y
Ad

Answer this question