I want to create a system where players can gift other players coins. like combat warriors.
the issue is that:
it does not print or work.
I have tried adding warnings to the code, and watching some tutorials.
Here is my server script
remoteevent = game:GetService("ReplicatedStorage"):WaitForChild("GiftSystemRE")
local DatastoreService = game:GetService("DataStoreService")
local Datastore = DatastoreService:GetDataStore("CurrencyStore", "Currency1")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
--
local Credits = Instance.new("IntValue")
Credits.Name = "credits"
Credits.Parent = leaderstats
Credits.Value = Datastore:GetAsync(Player.UserId) -- my key is plr.UserId
end)
game.Players.PlayerRemoving:Connect(function(Player)
local sucess, Error = pcall(function()
Datastore:SetAsync(Player.UserId, Player.leaderstats.credits.Value)
--
end)
while not sucess do
warn("Saving Failed.. Retrying")
end
-- save players datastore when they leave.
end)
function SavePLAYER()
local players = game:GetService("Players"):GetPlayers()
for i, Player_ in pairs(players) do
local sucess, Err = pcall(function()
Datastore:SetAsync(Player_.UserId, Player_.leaderstats.credits.Value)
end)
if sucess then
print("datasaved. bound to close.")
end
end
end
--[[
GIFTING SYSTEM [functions]
]]
remoteevent.OnServerEvent:Connect(function(plr: Player, amount: number, ID: number)
local COINS
local sucess, err = pcall(function()
COINS = Datastore:GetAsync(ID)
end)
if sucess then
local sucess2, error2 = pcall(function()
Datastore:SetAsync(ID, COINS + amount)
end)
if sucess2 then
print("gift sent.")
else
warn(error2)
end
end
end)
local DeveloperIDS = {
["TierOne"] = 1878086385, -- Sends 100 coins
["TierTwo"] = 120401241248, -- sends 500 coins
["TierThree"] = 1230581818 -- sends 1000 coins
}
local marketplaceservice = game:GetService("MarketplaceService")
function ProductReceipt(ReceiptInfo)
print("Gift Received???")
local player = game:GetService("Players"):GetPlayerByUserId(ReceiptInfo.PlayerId)
if ReceiptInfo.ProductId == DeveloperIDS.TierOne then
-- Send the tierONE:
if player then
remoteevent:FireClient(player, "Tier1")
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
elseif ReceiptInfo.ProductId == DeveloperIDS.TierTwo then
-- send the Tier two
if player then
remoteevent:FireClient(player, "Tier2")
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
elseif ReceiptInfo.ProductId == DeveloperIDS.TierThree then
-- send the tier 3
if player then
remoteevent:FireClient(player, "Tier3")
return Enum.ProductPurchaseDecision.PurchaseGranted
else
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
end
marketplaceservice.ProcessReceipt = ProductReceipt()
here is my client code:
local mPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
mPS:PromptProductPurchase(player, 1878086385)
end)
local remote = game:GetService("ReplicatedStorage").GiftSystemRE
remote.OnClientEvent:Connect(function(Type: string)
local player = game.Players.LocalPlayer
local target = game:GetService("Players"):GetUserIdFromNameAsync(script.Parent.Parent.TextBox.Text)
if Type == "Tier1" then
remote:FireServer(100, target)
elseif Type == "Tier2" then
remote:FireServer(500, target)
elseif Type == "Tier3" then
remote:FireServer(1000, target)
end
end)
Also:
Here is a SS