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

Where do I start with disabling a script for the localplayer?

Asked by
7z99 203 Moderation Voter
4 years ago

I have a script that does what I need it to, however after it executes once, I need it to be disabled for the person that ran the script. Does anyone have any examples or reference links for a starting point?

0
what is the context? royaltoe 5144 — 4y
0
script.Disabled = false will disable your script, but maybe we want to do something else royaltoe 5144 — 4y
0
A little background: This is a progress script (in the normal script) that adds about 0.005 every time a part is touched, however if the player touches the part more than once, it will add more than that. I want to prevent this by disabling the script, however the script should be enabled once again after the round is over. 7z99 203 — 4y
0
Can I see the code so far? We don't need to disable the script, more add something called a debounce . royaltoe 5144 — 4y
0
I was able to get it working, I will post an answer to this thread. 7z99 203 — 4y

1 answer

Log in to vote
0
Answered by
7z99 203 Moderation Voter
4 years ago
Edited 4 years ago

I was able to get some help on this on the Roblox Discord.

Essentially, what you need to do to get it working is have the block have a detector to detect what is touching it and who is touching it. Also add a delay to the top.

Script 1: (ServerScript)

--Ensure this is the child of the part you want to detect

local part = script.Parent -- Part the will activate when touched
local last = 0
local delay = 1000 --in seconds

part.Touched:Connect(function(hit)

    if tick() - last > delay then
        last = tick()
        if hit.Parent:FindFirstChildOfClass("Humanoid") ~= nil then -- If there is a humanoid in the parent of what touched the part

            local char = hit.Parent -- The Character of the player
   --if the arm touches it, hit is the arm and parent is the arm's parent

            local player = game.Players:GetPlayerFromCharacter(char) -- This gets the player in game.Players by getting the name from its character
            local playergui = player.PlayerGui --Where all gui are located into the player
            local gui = playergui.ScreenGui.ProgressBar.Config.Progress

            gui.Value = gui.Value + 0.005 -- Adds 0.005 to the value
        end
    end
end)

Script 2, to disable it: (LocalScript)

--Ensure this is is the child of the same script as above. You should also add a detector to ensure it's only being disabled when the parent part is touched.

local progressScript = script.Parent.Script

progressScript.Disabled = true

wait(600)

progressScript.Disabled = false
0
Glad you got it working! royaltoe 5144 — 4y
0
Instead of tick() - last > delay, there's another way to do it, I'll edit your answer to show you that royaltoe 5144 — 4y
0
I made an edit by adding a comment to one of the scripts but it removed yours, could you re-add it? 7z99 203 — 4y
Ad

Answer this question