How do i make this touched script so you can only touch it once and you cant touch it anymore?
function onTouched(hit) for i=0,1 ,0.1 do wait(0.1) script.Parent.Transparency = i end end script.Parent.Touched:connect(onTouched)
Use a debounce: Here is how it works. There is a debounce variable that could be anything. True or false. We say that if the variable is true, we can do the script. Then we change the debounce.
--Example script.Parent.Touched:connect(function() print("Hi") wait(3) print("Bye") end)
Output: Hi Hi Hi Hi Bye Bye Bye Bye
If we use a debounce, It would look like this.
--Example local debounce = false script.Parent.Touched:connect(function() if not debounce then --If the debounce is false debounce = true --Then turn it true so debounce is not false. print("Hi") wait(3) print("Bye") debounce = false --Make it usable after 3 seconds. end end)
Output: Hi Bye
Now we add this to your script:
local used = false function onTouched(hit) if not used then used = true for i=0,1 ,0.1 do wait(0.1) script.Parent.Transparency = i end used = false end end script.Parent.Touched:connect(onTouched)
Hope it helps!
Well, to make sure they don't touch it while it's running, set up a debounce. You also should check if it's a Player that touched it. To delete the script, use :Destroy() so..
local on = false function onTouched(hit) if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) and on == false then on = true for i = 0,1,0.1 do wait(0.1) script.Parent.Transparency = i end script:Destroy() end end script.Parent.Touched:connect(onTouched)