- I need to make it so that the player can activate the button activation and save once. But I don’t really understand how to do
this, there is an error in my code and when activating all players it writes to the table and only for one the button turns on
It would be great if someone would tell me what’s wrong and how to fix it, because I haven’t been able to find a solution for a week
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local Players = game:GetService("Players")
local Po1a = workspace.Folder.PointsTp:WaitForChild("Po1a")
local Po2b = workspace.Folder.PointsTp:WaitForChild("Po2b")
local Po3c = workspace.Folder.PointsTp:WaitForChild("Po3c")
local Po4d = workspace.Folder.PointsTp:WaitForChild("Po4d")
local Po5e = workspace.Folder.PointsTp:WaitForChild("Po5e")
local Po6f = workspace.Folder.PointsTp:WaitForChild("Po6f")
local Po7g = workspace.Folder.PointsTp:WaitForChild("Po7g")
local Po8h = workspace.Folder.PointsTp:WaitForChild("Po8h")
local Po9i = workspace.Folder.PointsTp:WaitForChild("Po9i")
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("PlayerVisibility")
local function saveVisible(player, buttonName, isVisible)
local key = buttonName .. "_".. player.UserId
dataStore:SetAsync(key, isVisible)
print("Saved " .. buttonName)
end
local function loadVisible(player, buttonName)
local key = buttonName .. "_" .. player.UserId
local success, isVisible = pcall(function()
return dataStore:GetAsync(key)
end)
if success then
print("Loaded")
return isVisible or false
else
return false
end
end
Players.PlayerAdded:Connect(function(player)
local buttonNames = {"Po1", "Po2", "Po3","Po4","Po5","Po6","Po7","Po8","Po9"}
for _, buttonName in pairs(buttonNames) do
local isVisible = loadVisible(player, buttonName)
local frame = player.PlayerGui:WaitForChild("TPmeny").Frame
if frame and frame[buttonName] then
frame[buttonName].Visible = isVisible
end
end
end)
local activatedPlayers1 = {}
local activatedPlayers2 = {}
local activatedPlayers3 = {}
local activatedPlayers4 = {}
local activatedPlayers5 = {}
local activatedPlayers6 = {}
local activatedPlayers7 = {}
local activatedPlayers8 = {}
local activatedPlayers9 = {}
game.Players.PlayerAdded:Connect(function(player)
Po1a.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not activatedPlayers1[player.UserId] then
activatedPlayers1[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po1.Visible = true
saveVisible(player, "Po1", true)
end
print(player.Name .. " activated Part1")
end
end)
Po2b.Touched:Connect(function(hit)
if player and not activatedPlayers2[player.UserId] then
activatedPlayers2[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po2.Visible = true
saveVisible(player, "Po2", true)
end
print(player.Name .. " activated Part2")
end
end)
Po3c.Touched:Connect(function(hit)
if player and not activatedPlayers3[player.UserId] then
activatedPlayers3[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po3.Visible = true
saveVisible(player, "Po3", true)
end
print(player.Name .. " activated Part3")
end
end)
Po4d.Touched:Connect(function(hit)
if player and not activatedPlayers4[player.UserId] then
activatedPlayers4[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po4.Visible = true
saveVisible(player, "Po4", true)
end
print(player.Name .. " activated Part4")
end
end)
Po5e.Touched:Connect(function(hit)
if player and not activatedPlayers5[player.UserId] then
activatedPlayers5[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po5.Visible = true
saveVisible(player, "Po5", true)
end
print(player.Name .. " activated Part5")
end
end)
Po6f.Touched:Connect(function(hit)
if player and not activatedPlayers6[player.UserId] then
activatedPlayers6[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po6.Visible = true
saveVisible(player, "Po6", true)
end
print(player.Name .. " activated Part6")
end
end)
Po7g.Touched:Connect(function(hit)
if player and not activatedPlayers7[player.UserId] then
activatedPlayers7[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po7.Visible = true
saveVisible(player, "Po7", true)
end
print(player.Name .. " activated Part7")
end
end)
Po8h.Touched:Connect(function(hit)
if player and not activatedPlayers8[player.UserId] then
activatedPlayers8[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po8.Visible = true
saveVisible(player, "Po8", true)
end
print(player.Name .. " activated Part8")
end
end)
Po9i.Touched:Connect(function(hit)
if player and not activatedPlayers9[player.UserId] then
activatedPlayers9[player.UserId] = true
if hit.Parent == player.Character then
player:WaitForChild('PlayerGui').TPmeny.Frame.Po9.Visible = true
saveVisible(player, "Po9", true)
end
print(player.Name .. " activated Part9")
end
end)
end)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild('Humanoid').Died:Connect(function ()
wait(4)
local buttonNames = {"Po1", "Po2", "Po3","Po4","Po5","Po6","Po7","Po8","Po9"}
for _, buttonName in pairs(buttonNames) do
local isVisible = loadVisible(player, buttonName)
local frame = player.PlayerGui:WaitForChild("TPmeny").Frame
if frame and frame[buttonName] then
frame[buttonName].Visible = isVisible
end
end
end)
end)
end)