Permanently disappear

I am trying to make a system where if you touch a part it does some effects and that the effect only happens once and never again even if you rejoin.

The current script i have is this →

local block = script.Parent
local debounce = true
local Tween = game.TweenService:Create(script.Parent,TweenInfo.new(0.8,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Size = Vector3.new(8.927, 1, 8.756); Transparency = 1})

block.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA(“Humanoid”)
if humanoid and debounce == true then
debounce = false
Tween:Play()
block.Transparency = 0
block.Size = Vector3.new(5.232, 1, 5.323)
wait(1)
script:Destroy()
end
end)

I am trying to get it so that the script is permanently disappeared but idk how to do that. can someone help me?

A single-run script doesn’t require itself to be destroyed. You can disconnect the function instead.

local block = script.Parent
local debounce = true
local Tween = game.TweenService:Create(script.Parent,TweenInfo.new(0.8,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Size = Vector3.new(8.927, 1, 8.756); Transparency = 1})
local connection

connection = block.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChildWhichIsA(“Humanoid”)
	if humanoid and debounce == true then
		debounce = false
		Tween:Play()
		block.Transparency = 0
		block.Size = Vector3.new(5.232, 1, 5.323)
		wait(1)
		connection:Disconnect()
        connection = nil -- memory clean, ooo shiny
	end
end)

Do you mean you want it to never happen to that player again, but it still works for other players? Or do you mean that it happens for nobody else in the server ever again. Or do you mean that once one player touches it it doesn’t work for anyone across any server?

I want it to be so that it never happens again for that certain player only

its not working… I dont know why

Add whoever touches the part to a table, and don’t do anything if a certain player touched the part and was found in the table.

For cross server communication, you would have to utilize data stores.

local DataStore = game:GetService("DataStoreService"):GetDataStore("Store")

local block = script.Parent
local Tween = game.TweenService:Create(script.Parent,TweenInfo.new(0.8,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Size = Vector3.new(8.927, 1, 8.756); Transparency = 1})

local blackListedPlayers = {}
local saving = {}

block.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) or game:GetService("Players"):GetPlayerFromCharacter(hit.Parent.Parent)
    if not player then
        return
    end	

	if blackListedPlayers[player.Name] == nil or DataStore:GetAsync(player.UserId) == nil  and saving[player.Name] == nil then
        blackListedPlayers[player.Name] = true
        saving[player.Name] = true -- If the same player touched
        -- the part again, SetAsync will be called again unnecessarily
        -- and thus throttle, which isnt ideal at all

        DataStore:SetAsync(player.UserId, true)
        saving[player.Name] = nil 

		Tween:Play()
		block.Transparency = 0
		block.Size = Vector3.new(5.232, 1, 5.323)
	end
end)

PS:

You don’t need to destroy the script if you only want the code to run for players who never touched the part.

@XdJackyboiiXd21

That will not work, you’re saving a boolean false, and not false will return true.

2 Likes

Then you would have to save it to a datastore.

local datastore = game:GetService("DataStoreService"):GetDataStore("PartTouched")
local block = script.Parent
local debounce = true
local Tween = game.TweenService:Create(script.Parent,TweenInfo.new(0.8,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Size = Vector3.new(8.927, 1, 8.756); Transparency = 1})
       
block.Touched:Connect(function(hit)
       local humanoid = hit.Parent:FindFirstChildWhichIsA(“Humanoid”)
       if humanoid and debounce == true and not datastore:GetAsync(game.Players:GetPlayerFromCharacter(hit.Parent).UserId) then
           datastore:SetAsync(player.UserId, false)
           debounce = false
           Tween:Play()
           block.Transparency = 0           
           block.Size = Vector3.new(5.232, 1, 5.323)
           wait(1)
      end
end)

Also happy birthday @SilentsReplacement!

1 Like

Another consideration is to use a global DataStore, because it is not cross-server exactly. Unfortunately with the information provided, it is still ambiguous what @OP exactly wants.

I never saw that OP wanted to have it work with cross server, I’ll edit my post.

1 Like

none of this is working for me I have tried others way just to fail

What errors are you getting, at least provide some context in order for people to try and solve your problem.

there is no error in output but its just not working but I dont need to solve this anymore. Thank you for trying to help me tho :slight_smile: