Hi, my name is baccon. I’m trying to make a system where you can save tickets, trade tickets, add tickets, and remove tickets but I’m having an bit of an issue. So every time I try to call the event I get an error:
ServerScriptService.PlayerMain.136: Attempt To Index Nil 'Folder1'
I’m very confused on what could be happening. Could any one help me?
Here’s The Code.
--// Get Services
local Lighting = game:GetService( 'Lighting' )
local ReplicatedStorage = game:GetService( 'ReplicatedStorage' )
local ServerStorage = game:GetService( 'ServerStorage' )
local Teams = game:GetService( 'Teams' )
local Market = game:GetService('MarketplaceService')
local teleportService = game:GetService("TeleportService")
local DataStoreService = game:GetService("DataStoreService")
--// Define Variables
local Admins = {0, 0}
local Banned = {0}
local GameValues = workspace:WaitForChild( 'GameValues' )
local Field = workspace:WaitForChild( 'Locker' )
local RemoteEvent = Instance.new( 'RemoteEvent', ReplicatedStorage )
local RemoteFunction = Instance.new( 'RemoteFunction', ReplicatedStorage )
local Event = Instance.new("RemoteEvent", ReplicatedStorage)
Event.Name = "Event"
--// DataStoreService
local Players = game:GetService("Players")
local TicketsData = DataStoreService:GetDataStore("TicketsData1")
local ServerData = {}
local function NewData()
return {
Folder1 = {
Tickets = 0,
},
}
end
local function LoadData(Player)
local Data
local Success, Error = pcall(function() Data = TicketsData:GetAsync("Data:"..Player.UserId) end)
if not Success then
warn("Could not get data for: "..Player.Name)
end
if not Data then
Data = NewData()
end
ServerData[Player] = Data
end
local function SaveData(Player)
if ServerData[Player] then
local Success, Error = pcall(function() TicketsData:SetAsync("Data:"..Player.UserId, ServerData[Player]) end)
if not Success then
warn("Could not save data for: "..Player.Name)
return
end
ServerData[Player] = nil
end
end
--// function
function OnList(List, UserId)
for _,v in pairs(List) do
if v == UserId then
return true
end
end
return false
end
function Countdown()
end
function Caught_Exploiting()
--// Catching Exploiter Messing With Data Or Bypassing Countdown
end
function searchPlayer(player,id)
local success, wasFound, errorMessage, placeId, jobId = pcall(function()
return teleportService:GetPlayerPlaceInstanceAsync(id)
end)
if success then
return placeId, jobId
else
return "Error"
end
end
--// Main Scripting
--// Player Aadded
game.Players.PlayerAdded:Connect(function(Plr)
wait()
LoadData(Plr)
Plr.CharacterAdded:Connect(function(Char)
Char.Humanoid.WalkSpeed = 0
end)
if OnList(Banned, Plr.UserId) then
print(Plr.Name..' Is On The Banned List, Please Contact OFA staff to be unbanned.')
Plr:Kick(Plr.Name..' Is On The Banned List, Please Contact OFA staff to be unbanned.')
--table.insert(Plr.UserId, Banned)
elseif not OnList(Banned, Plr.UserId) then
print('Clean')
end
end)
--// Player Removed
game.Players.PlayerRemoving:Connect(function(Plr)
SaveData(Plr)
end)
--
game:BindToClose(function()
for _,Players in pairs(game.Players:GetPlayers()) do
SaveData(Players)
end
end)
--// Player Purcahsing
Market.ProcessReceipt = function(info)
if info.ProductId == 1108007995 then
local Playeeee = game.Players:GetPlayerByUserId(info.PlayerId, "15")
print('Thingy')
ServerData[Playeeee].Folder1.Tickets = ServerData[Playeeee].Folder1.Tickets + 1
print(ServerData[Playeeee].Folder1.Tickets)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
--// Remote RemoteEvent
RemoteEvent.OnServerEvent:Connect(function(Plr, Input)
if Input[1] == 'CaughtSlippin' then
--Exploiting Their Way Into A Ticket
elseif Input[1] == 'SearchForPlayer' then
local ID = Input[2]
searchPlayer(Plr, ID)
elseif Input[1] == 'StarbowlCountdownFinished' then
print('Starbowl Open')
end
end)
--// Remote Functions
RemoteFunction.OnServerInvoke = function(Plr, Input)
if Input[1] == 'AddTickers' then
local Amount = Input[2]
local Player = Input[3]
ServerData[Player].Folder1.Tickets = ServerData[Player].Folder1.Tickets + Amount
print(Player, ServerData[Player].Folder1.Tickets)
elseif Input[1] == 'RemoveTickets' then
local Amount = Input[2]
local Player = Input[3]
ServerData[Player].Folder1.Tickets = ServerData[Player].Folder1.Tickets - Amount
print(Player, ServerData[Player].Folder1.Tickets)
elseif Input[1] == 'ReturnTicketsValue' then
end
end