Hello!
So I'm trying to make a progress system, and basically the system works as this:
1- The user touches the brick 2- The script adds a value to a progressbar 3- The script is either disabled or the brick is deleted entirely so the same brick can't add more to the progressbar.
This should happen for the localplayer only.
Here's the code I tried, in a localscript:
function addProgress() print("a") game.Players.LocalPlayer.StarterGUI.ScreenGUI.ProgressBar.Config.Progress.Value = game.Players.LocalPlayer.StarterGUI.ScreenGUI.ProgressBar.Config.Progress.Value + 0.54 script.Disabled = true end script.Parent.Touched:Connect(addProgress)
The prime issue here is that the script isn't executing at all, as "a" isn't being outputted.
I believe you are supposed to use PlayerGui
instead of StarterGUI
as StarterGUI
is a service that replicates its contents to PlayerGui
which the player has upon joining.
Also, you are disabling the script at any part touching it. To actually have it activate once a player touches it, check if a player does touch it with an if statement.
if hit.Parent:GetPlayerFromCharacter() then —your code end
If you want it to activate for NPCs as well then replace it if Humanoid exists
if hit.Parent:FindFirstChild(“Humanoid”) then — i dont know what living being would have a humanoid named something else but if this is true for you, you would use findfirstchildofclass —your code end
If you are no longer using the script after the function, don’t just disable it, remove it. Unless you are enabling it again, it is better to get rid of it.
script:Destroy()