Why isnt my script properly working?

It should work fine, but I don’t know where I messed up.

devfourmhelpscripting

If you can help me figure this out that would be cool.

edit: I just realized that I had posted this without any context.

I am trying to script it so that when Dummy1 is killed it activates the wanted level at the top right. If it works, the singular cop at the far right should not be transparent. I have not found any way to fix this problem, but knowing my luck its probably a simple solution. Im running this with a Script, not a Local Script.

3 Likes

Make sure you are scripting any gui in a localscript, in this case you are only changing startergui, not PlayerGui - PlayerGui | Documentation - Roblox Creator Hub

Please tell me what you are trying to achieve here so I can provide you better help.

4 Likes

I agree with @corotines. If you want help, please give as much information as possible.

Is this your entire script?
What is the script supposed to do?
What have you tried?
Are there any erros in Output?

1 Like

StarterGUI is used for placing GUI elements in that will be cloned to the player when they join the game. Attempting to change the GUI elements through Starter GUI won’t change the player’s GUI (the link in @corotines reply will probably explain this in more depth). I suggest using a local script as stated above and using something like this:

local WantedLevel = game.Players.LocalPlayer.PlayerGui.ScreenGui.wanted1

Please note that you will need to delay this variable by a few seconds so that the player can load in fully before defining this variable.

This will only work in a local script but will do what you need. If errors still persist you should help clarify what @Secretum_Flamma has said above.

5 Likes

Okay, I just added more information to the post. (sorry for making the post without the proper information!)

1 Like

Try changing
WantedLevel.ImageTransparency = 1
to
WantedLevel.ImageTransparency = 0

If you set it to 1, the image will be 100% transparent. Setting it to 0 makes it 0% transparent.

1 Like

Yeah, but either way it does not go visible or invisible. But ill try it!

1 Like

I’ve done some experimenting in Studio, and it seems this issue is related to the GUI itself, not scripting. The print is saying 1, and checking it does show the value changed to 1, however this change isn’t reflected in the actual GUI.

My Code, in StarterPlayerScripts

local hs = game.Workspace.Secretum_Flamma1.Humanoid

local playergui = script.Parent.Parent.PlayerGui.WLGUI.Frame.number.Text

hs.HealthChanged:Connect(function(Health)

if hs.Health <= 0 then

playergui = 1 print(playergui)

end

end)

while true do

wait(1)

print(playergui)

end```
2 Likes

You can’t edit from the StarterGui you have to edit from the PlayerGui or else nothing will happen because the player won’t get the same change on the PlayerGui

Im not a professional scripter but use the developer wiki if you want to accomplish what ever you need to be done.
Use this link:

1 Like

Ok so you need the NPC to execute the wanted level. The NPC is server side (not a part of the player). Players (client side) are stopped from being able to talk to the server, EXCEPT through remote events, or things like replicated storage.

So If the NPC dies, it then changes a variable somewhere that is the “WantedLevel” I would use and intValue object and then anything can access that variable and react apropriately. But if you have a script that handles all the variables, you may need to use that binding thing.

Anyway Server now knows Wanted is active. It then sends a message to the StartGui saying “Wanted Level is now 2.” So the Player (local script inside the starter gui or starterscripts) then goes. “Oh ok. I’ve been told. I will now change the transparency of my image.”

Point being, you really should keep them separate and have them Tell each other only the important information.

Aditionally, you want to have your Image in the Gui where the local script is that handles the remote event. That way you just have

local WantedLevel = script.Parent.wanted1

That way, you don’t need to know where it is or anything. The wanted Gui will handle itself without any other hassles.

Alternatively, if you are a script based coder you will need to tell the script where everything is in relation to the script. I don’t do this. I tend to have each object handle itself and communicate any needed information to other objects.

It’s like a bunch of people working together each handling their own thing, rather than like one big super computer doing the work of like 20 people.

So in the end, just make the Wanted Level Gui wait for the remote event and when it gets it, it just changes the transparency.

The NPC when it dies, either tells the Gui to show the wanted level, or it tells the main script (through like and IntValue) that the wanted level is rising. That way the main script can determine when to trigger the next level of the wanted level.

1 Like