Locally disabling script temporarily

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Make so when a player touches a part, the script only gives one win instead of repeatingly giving wins.
  2. What is the issue? Include screenshots / videos if possible!
    Its giving 10-20 wins
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Original Script

amnt = 1 --how much you get for it
function onTouched(part)
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Wins")
				if (score~=nil) then
					score.Value = score.Value + amnt
				end
			end
		end
		script.Parent:remove()
	end
end

script.Parent.Touched:connect(onTouched)

i tried local script:disable instead of delete parent, but couldn’t figure out how to make it still work for the second round. i think it needs to use module scripts/local events?

if I don’t disable it it gives 10-20 wins.
the part is overlapped by an exact clone of exact size and position that has a teleport script inside. (tp within a place, btw)

script.Disabled = true

And to enable it

script.Disabled = false

But I dont recommend doing that, add a debounce instead (NOTE: enabling it again will restart the script)

1 Like

Please add Db (Debounce)

For example:

local denounce = true
script.Parent.Touched:Connect(funtion(hit)
 if debounce == true then
 denounce = false
 print("hit 1 time")
 end
end)

so

local debounce = true
script.Parent.Touched:Connect(funtion(hit)
if debounce == true then
debounce = false
print(“hit 1 time”)
end
end)
amnt = 1 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild(“Humanoid”)
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild(“leaderstats”)
if (stats~=nil) then
local score = stats:findFirstChild(“Wins”)
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
local script:disable
end
end

script.Parent.Touched:connect(onTouched)

Yes. Try that

Note: This will run 1 time only.

or do i put that in place of disable script

Wait i suggest you to use local script and normal script both then fire it.
For example…

also make sure to disable the debounce again after another round

Changing the property script.Disabled will disable the script. The script can be disabled itself, but once disabled, the script won’t run (so it won’t enable itself, neither.)

1 Like

Okay so

  • Insert a remote event in replicated storage
  • create a local script in the part.
  • create a script in ServerScriptService

then type the following code in Local Script

local db = true
function onTouched(part)
    if db then
       db = false
       game.ReplicatedStorage.RemoteEvent:FireServer(part)
    end
end
script.Parent.Touched:Connect(onTouched)

Now type the following code in the Server Script

function server(plr,part)
  amnt = 1 --how much you get for it
	local h = part.Parent:findFirstChild("Humanoid")
	if (h~=nil) then
		local thisplr = game.Players:findFirstChild(h.Parent.Name)
		if (thisplr~=nil) then
			local stats = thisplr:findFirstChild("leaderstats")
			if (stats~=nil) then
				local score = stats:findFirstChild("Wins")
				if (score~=nil) then
					score.Value = score.Value + amnt
				end
			end
		end
	end
  end
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(server)

its not giving any output, but its not working :expressionless:

Hmm wait I forgot to put remote event.

put game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(server)