I'm trying to do this with every way I can and some ways are like never gonna work, it's weird but I hope I can find an answer to this question. I'm trying to make it so that if a player touches the brick, he can never touch it again or the code inside the touched event will never run again even if he rejoins Here's the code I tried and didn't work.
local debounce = true script.Parent.Touched:Connect(function(plr) if plr.Parent:FindFirstChild("Humanoid") then script.Parent.BrickColor = BrickColor.new("Really red") debounce = false game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(player) debounce = false end) end) end end)
I tried my best ok?
Script
A ServerScript inside a part inside the workspace.
Thanks.
I believe you are trying to make it one-time touch part.
I think you'll need to use DataStore.
Script inside your part:
script.Parent.Touched:Connect(function(hit) local playerCharacter = hit.Parent.Name local player = game.Players[playerCharacter] local partDebounce = player.canTouch if partDebounce.Value == false then -- if the value of canTouch boolean is false partDebounce.Value = true -- do whatever you want else print("player cant touch this part anymore") end end)
Script inside ServerScriptService:
local DataStore = game:GetService("DataStoreService") local debounceData = DataStore:GetDataStore("YourDataStoreHere") game.Players.PlayerAdded:Connect(function(plr) local canTouchPart = Instance.new("BoolValue") canTouchPart.Name = "canTouch" canTouchPart.Parent = plr local data = debounceData:GetAsync(plr.UserId) if data then plr.canTouch.Value = data end end) local function saveData(plr) local data data = plr.canTouch.Value debounceData:SetAsync(plr.UserId, data) end game.Players.PlayerRemoving:Connect(function(plr) -- runs when player leaves saveData(plr) end) game:BindToClose(function() wait(1) -- runs when game shutdowns for _, v in pairs(game.Players:GetPlayers()) do if v then saveData(v) end end end)
I haven't tested if the data works, but you can try and let me know!