I was working on a Equip/Unequip Script for a small shop in my game. It was working earlier with remote events and such, whenever I add in Data Store to server script (In A Different Function), it stops sending remote events entirely. No Errors, it stops sending and receiving completely. This happened for the purchase local script, equip local script, and the handler server script.
The variables are fine, no inf yields.
Server:
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local ServerDeathItems = ServerStorage:WaitForChild("GameItems"):WaitForChild("DeathShop")
local DeathShopItems = RepStorage:WaitForChild("DeathShop")
local DeathShopRemoteEvent = RepStorage:WaitForChild("DeathShop"):WaitForChild("DeathShopHandler")
local DataStoreService = game:GetService("DataStoreService")
local DeathShopStore = DataStoreService:GetDataStore("DeathShopData")
local Data
local DeathInv = {
["Im Dead!"] = false
}
local function SaveDeathInv(Player)
local SavedDeathInventory = {
Player.DeathShopItems:WaitForChild("Im Dead!").Value,
}
local success = pcall(DeathShopStore:SetAsync(Player.UserId, SavedDeathInventory))
end
Players.PlayerAdded:Connect(function(Player)
local Data
local success, response = pcall(function()
Data = DeathShopStore:GetAsync(Player.UserId)
end)
local DeathShopFolder = Instance.new("Folder", Player)
DeathShopFolder.Name = "DeathShopItems"
for Name, Value in pairs(DeathInv) do
local Bool = Instance.new("BoolValue", DeathShopFolder)
Bool.Name = Name
local success, response = pcall(function()
Player.DeathShopItems:FindFirstChild("Im Dead!").Value = Data[1]
end)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
SaveDeathInv(Player)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
SaveDeathInv(Player)
end
end)
while task.wait(60) do
for _, Player in pairs(game.Players:GetPlayers()) do
SaveDeathInv(Player)
end
end
DeathShopRemoteEvent.OnServerEvent:Connect(function(Player, Item, Identifier)
if Identifier == "Purchase" then
local Price = tonumber(DeathShopItems:FindFirstChild(Item).Price.Value)
local ItemBought = DeathShopItems:FindFirstChild(Item).DeathTitle.Value
Player.leaderstats.moneyFolder.Money.Value = Player.leaderstats.moneyFolder.Money.Value - Price
Player:WaitForChild("DeathShopItems"):WaitForChild(ItemBought).Value = true
end
end)
DeathShopRemoteEvent.OnServerEvent:Connect(function(Player, Item, Identifier)
if Identifier == "Equip" then
for _, SpecialItem in pairs(Player.Backpack:GetChildren()) do
if SpecialItem:IsA("Tool") then
if SpecialItem:FindFirstChild("isSpecial") then
SpecialItem:Destroy()
end
end
end
for _, SpecialItem in pairs(Player.StarterGear:GetChildren()) do
if SpecialItem:IsA("Tool") then
if SpecialItem:FindFirstChild("isSpecial") then
SpecialItem:Destroy()
end
end
end
local ItemName = RepStorage:WaitForChild("DeathShop"):FindFirstChild(Item)
local ItemBought = ServerDeathItems:WaitForChild(ItemName.DeathTitle.Value)
local ClonedItem = ItemBought:Clone()
local ClonedItem2 = ItemBought:Clone()
ClonedItem.Parent = Player.StarterGear
ClonedItem2.Parent = Player.Backpack
else if Identifier == "Unequip" then
for _, SpecialItem in pairs(Player.Backpack:GetChildren()) do
if SpecialItem:IsA("Tool") then
if SpecialItem:FindFirstChild("isSpecial") then
SpecialItem:Destroy()
end
end
end
for _, SpecialItem in pairs(Player.StarterGear:GetChildren()) do
if SpecialItem:IsA("Tool") then
if SpecialItem:FindFirstChild("isSpecial") then
SpecialItem:Destroy()
end
end
end
end
end
end)
Purchase Local Script:
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeathShopRemoteEvent = ReplicatedStorage:WaitForChild("DeathShop"):WaitForChild("DeathShopHandler")
local PurchaseSound = script:WaitForChild("PurchaseSound")
local Clicked = false
script.Parent.MouseButton1Down:Connect(function()
if not Clicked then
Clicked = true
local ItemPrice = tonumber(ReplicatedStorage:WaitForChild("DeathShop"):FindFirstChild(script.Parent.Parent.ItemName.Value).Price.Value)
if Player.leaderstats.moneyFolder.Money.Value >= ItemPrice then
DeathShopRemoteEvent:FireServer(tostring(script.Parent.Parent.ItemName.Value), "Purchase")
print(tostring(script.Parent.Parent.ItemName.Value))
PurchaseSound:Play()
script.Parent.Visible = false
task.wait(1)
script.Parent.Parent.EquipDeath.Visible = true
if Clicked then
Clicked = true
end
end
end
end)
Equip Script:
local Player = game.Players.LocalPlayer
local Character = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Character:WaitForChild("Humanoid")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DeathShopRemoteEvent = ReplicatedStorage:WaitForChild("DeathShop"):WaitForChild("DeathShopHandler")
local EquipSound = script:WaitForChild("EquipSound")
local Clicked = false
script.Parent.MouseButton1Up:Connect(function()
if not Clicked then
Clicked = true
EquipSound:Play()
if script.Parent.Text == "[Equip]" then
DeathShopRemoteEvent:FireServer(tostring(script.Parent.Parent.ItemName.Value), "Equip")
script.Parent.Text = "[Unequip]"
else if script.Parent.Text == "[Unequip]" then
DeathShopRemoteEvent:FireServer(tostring(script.Parent.Parent.ItemName.Value), "Unequip")
script.Parent.Text = "[Equip]"
end
end
task.wait(3)
if Clicked then
Clicked = false
end
end
end)