Hello!
The script below should set the first index of a player’s table called door data from 0 to 1 when the “RemoveDoor1” RemoteEvent is fired. However, the script fails to do so. What could be causing the issue? The issue can be found in the last function. The script is able to properly load in and save a table from the DataStores.
local openGui = game.ReplicatedStorage:WaitForChild("OpenDoor1Gui")
local door = game.Workspace:WaitForChild("Zone1Door")
local purchaseGui = game.StarterGui.Door1PurchaseGUI.Frame
local event = game.ReplicatedStorage:WaitForChild("RemoveDoor1")
local DataStoreService = game:GetService("DataStoreService")
local DoorsUnlocked = DataStoreService:GetDataStore("DoorsUnlocked")
local DoorData = {}
game.Players.PlayerAdded:Connect(function(player)
DoorData[player] = DoorsUnlocked:GetAsync(player.UserId)
warn("Door Data Loaded!")
print(DoorData[player])
if not DoorData[player] then
DoorData[player] = {0, 0}
DoorsUnlocked:SetAsync(player.UserId, DoorData[player])
warn("New Data Created!")
end
if DoorData[1] == 1 then
event:FireClient(player)
warn("Event Fired!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
DoorsUnlocked:SetAsync(player.UserId, DoorData[player])
DoorData[player] = nil
warn("Door Data Saved!")
end)
door.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player or not player:IsA("Player") then return end
local tokens = player.leaderstats.Tokens
local debounce = false
if tokens.Value >= 3000 and debounce == false then
debounce = true
openGui:FireClient(player)
task.wait(0.5)
debounce = false
end
end)
event.OnServerEvent:Connect(function(player)
local tokens = player.leaderstats.Tokens
tokens.Value -= 3000
DoorData[1] = 1
print(DoorData[player])
end)
Thanks!