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

How can I delete a brick/disable a script for the localplayer?

Asked by
7z99 203 Moderation Voter
4 years ago
Edited 4 years ago

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.

1 answer

Log in to vote
0
Answered by
aredanks 117
4 years ago
Edited 4 years ago

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()
0
Thanks! I'll test this out. 7z99 203 — 4y
0
I tested it to no avail. I think the issue is that it isn't executing as "a" is not printed into the output. 7z99 203 — 4y
0
I believe the function executes but any part it touches will register the function which since you are disabling the script the moment that happens is likely the cause of your problem. I will fix the answer and re-edit. aredanks 117 — 4y
0
I edited my answer, this should fix it now for you. aredanks 117 — 4y
View all comments (3 more)
0
I'm gonna look over it now. Thanks! 7z99 203 — 4y
0
I have a question regarding the first part: Should I just remove the function entirely and replace it with the if statement or should I put the if statement into the function? 7z99 203 — 4y
0
I think you should just add the if statement, remove the script.Disabled part and just destroy the script instead. While you can definitely use the .Disabled if you want, I'd recommend Destroy as per what I explained in the answer. aredanks 117 — 4y
Ad

Answer this question