1 time purchase per item

Incase i keep replying here
gfdg.rbxl (207.6 KB)
thats it here go to starter GUI and purchase UI and click the frame there is the buy button with the handler but if u want the save script go to server script service

there HandleSavingTools

1 Like

I’m quoting the code you sent in Post 1 and Post 10. Sorry if I confused you; none of it is newly written code. I added two comments to mark which places I’m referring to.


if plr:WaitForChild("Purchase"):WaitForChild("SlingShot").Value == true then
    table.insert(datasave, NamePass.Value)
end
-- code continues...

Try replacing this part of code Post 1 with the code above. You might have to change NamePass.Value so it correctly refers to the value of NamePass.

2 Likes

what about data save this one?

local DataStoreService = game:GetService("DatastoreService")
local ds = DataStoreService:GetDataStore("datatest")

wichh one?

full code

local Name = script.Parent.Name
local Robux = script.Parent.Robux
local Imageid = script.Parent.Image
local BoolIfOwns = script.Parent.SlingShot
local plr = game.Players.LocalPlayer.PlayerGui.Purchase

local DataStoreService = game:GetService("DatastoreService")
local ds = DataStoreService:GetDataStore("datatest")

print("Running Robux Purchases")

while wait() do
	if script.Parent.Parent.InsidePurchase then
	script.Parent.Title.Text = tostring(script.Parent.NamePass.Value)  --does the name first
		script.Parent.Price.Text = tostring(script.Parent.Robux.Value) 
		script.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id="..tostring(Imageid.Value)
		Robux.Value = string.gsub(Robux.Value, "^(-?%d+)(%d%d%d)", '%1,%2')
		if Robux.Value == "0" then
			Robux.Value = "Free"
		end
	end
end

if plr:WaitForChild("Purchase"):WaitForChild("SlingShot").Value == true then
	table.insert(datasave, Name.Value)
end


ehmmm why loop reply @GreatPanda3

There are a few issues with the code.

When I first ran the game, I got these errors:

17:24:20.185 Purchase is not a valid member of ReplicatedStorage “ReplicatedStorage” - Server - Handle:5

  • The “Purchase” event isn’t in ReplicatedStorage.

17:24:22.748 ‘DatastoreService’ is not a valid Service name - Client - Handler:6

  • The correct spelling is DataStoreService (with a capital S for Store).

17:24:22.976 currency is not a valid member of Player “Players.GreatPanda3” - Client - Howmuch:3

  • The player’s currency value is accessed before it’s even created, but this is unrelated.

Another problem is DataStoreService can only be used in Server Scripts, not Local Scripts (like the Handler script).


Having seen the place itself, I’m confused about whether the code you sent at the beginning of the thread is one or two separate scripts. Can you please clarify this?

i dont use handle script in server script service so ignore that and the script in howmuch works still

local Name = script.Parent.Name
local Robux = script.Parent.Robux
local Imageid = script.Parent.Image
local BoolIfOwns = script.Parent.SlingShot
local plr = game.Players.LocalPlayer.PlayerGui.Purchase

local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("datatest")

print("Running Robux Purchases")

while wait() do
	if script.Parent.Parent.InsidePurchase then
	script.Parent.Title.Text = tostring(script.Parent.NamePass.Value)  --does the name first
		script.Parent.Price.Text = tostring(script.Parent.Robux.Value) 
		script.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id="..tostring(Imageid.Value)
		Robux.Value = string.gsub(Robux.Value, "^(-?%d+)(%d%d%d)", '%1,%2')
		if Robux.Value == "0" then
			Robux.Value = "Free"
		end
	end
end

if plr:WaitForChild("Purchase"):WaitForChild("SlingShot").Value == true then
	table.insert(datasave, Name.Value)
end


for handler in purchase

Your code originally included a while loop, and I’m only repeating the code you sent. Sorry if I’ve confused you. With my changes, the two scripts you sent would turn out as below.

You don’t need to remove game.Players.PlayerAdded and game.Players.PlayerRemoving if you need them, but know that DataStoreService can’t be used in Local Scripts.

-- the first code snippet, sent in Post 1 - see game.Players.PlayerRemoving connection
local Name = script.Parent.Name
local Robux = script.Parent.Robux
local Imageid = script.Parent.Image
local BoolIfOwns = script.Parent.SlingShot

local DataStoreService = game:GetService("DatastoreService")
local ds = DataStoreService:GetDataStore("datatest")

print("Running Robux Purchases")

while wait() do
	if script.Parent.Parent.InsidePurchase then
	script.Parent.Title.Text = tostring(script.Parent.NamePass.Value)  --does the name first
		script.Parent.Price.Text = tostring(script.Parent.Robux.Value) 
		script.Parent.ImageLabel.Image = "http://www.roblox.com/asset/?id="..tostring(Imageid.Value)
		Robux.Value = string.gsub(Robux.Value, "^(-?%d+)(%d%d%d)", '%1,%2')
		if Robux.Value == "0" then
			Robux.Value = "Free"
		end
	end
end

game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder",plr)
	Folder.Name = "Purchase"
	local BoolValue = Instance.new("BoolValue",Folder)
	BoolValue.Name = "SlingShot"

	local dataofuser = ds:GetAsync(plr.UserId)
	if dataofuser ~= nil then -- anything but nil
		print("Found data for " .. plr.Name)
		BoolValue.Value = ds[1]
	else
		print("Replacing no data with new data.")
		BoolValue = false
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}

    -- this is the only change made throughout this snippet
    if plr:WaitForChild("Purchase"):WaitForChild("SlingShot").Value then
        table.insert(datasave, NamePass.Value)
    end
	
	local success,response = pcall(function()
		ds:SetAsync(plr.UserId, datasave)
	end)

	if success then
		print("succesfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)
-- the second script, sent in Post 10 - completely unchanged
local toolfolder = game:GetService("ServerStorage"):FindFirstChild("Tools")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")

game.Players.PlayerAdded:Connect(function(Player)
	local ToolData = SaveData:GetAsync(Player.UserId)
	
	local Backpack = Player:WaitForChild("Backpack")
	local StarterGear = Player:WaitForChild("StarterGear")
	
	if ToolData ~= nil then
		for i, v in pairs(ToolData) do
			if toolfolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) ==nil then
				toolfolder[v]:Clone().Parent = Backpack
				toolfolder[v]:Clone().Parent = StarterGear
			end
		end
	end
	
	Player.CharacterRemoving:Connect(function(Character)
		Character:WaitForChild("Humanoid"):UnequipTools()
	end)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local ToolTable = {}
	for i, v in pairs(Player.Backpack:GetDescendants()) do
		table.insert(ToolTable, v.Name)
	end
	if ToolTable ~= nil then
		SaveData:SetAsync(Player.UserId, ToolTable)
	end
end)
1 Like

what sould i do then??? if i cant use it on local script ain’t working too

If the Handler is a Local Script, then I would recommend moving the game.Players.PlayerAdded and game.Players.PlayerRemoving connections to HandleSavingTools (a script you have in ServerScriptService) to prepare the player’s folders and load their data.

local Name = game.StarterGui.Purchase.Name will this work on server script???

-- the second script, sent in Post 10 - completely unchanged
local toolfolder = game:GetService("ServerStorage"):FindFirstChild("Tools")
local DataStoreService = game:GetService("DataStoreService")
local SaveData = DataStoreService:GetDataStore("SaveData")

local Name = game.StarterGui.Purchase.Name

game.Players.PlayerAdded:Connect(function(Player)
	local ToolData = SaveData:GetAsync(Player.UserId)

	local Backpack = Player:WaitForChild("Backpack")
	local StarterGear = Player:WaitForChild("StarterGear")

	if ToolData ~= nil then
		for i, v in pairs(ToolData) do
			if toolfolder:FindFirstChild(v) and Backpack:FindFirstChild(v) == nil and StarterGear:FindFirstChild(v) ==nil then
				toolfolder[v]:Clone().Parent = Backpack
				toolfolder[v]:Clone().Parent = StarterGear
			end
		end
	end

	Player.CharacterRemoving:Connect(function(Character)
		Character:WaitForChild("Humanoid"):UnequipTools()
	end)
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local ToolTable = {}
	for i, v in pairs(Player.Backpack:GetDescendants()) do
		table.insert(ToolTable, v.Name)
	end
	if ToolTable ~= nil then
		SaveData:SetAsync(Player.UserId, ToolTable)
	end
end)


game.Players.PlayerAdded:Connect(function(plr)
	local Folder = Instance.new("Folder",plr)
	Folder.Name = "Purchase"
	local BoolValue = Instance.new("BoolValue",Folder)
	BoolValue.Name = "SlingShot"

	local dataofuser = SaveData:GetAsync(plr.UserId)
	if dataofuser ~= nil then -- anything but nil
		print("Found data for " .. plr.Name)
		BoolValue.Value = SaveData[1]
	else
		print("Replacing no data with new data.")
		BoolValue = false
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local datasave = {}

	-- this is the only change made throughout this snippet
	if plr:WaitForChild("Purchase"):WaitForChild("SlingShot").Value then
		table.insert(datasave, Name.Value)
	end

	local success,response = pcall(function()
		SaveData:SetAsync(plr.UserId, datasave)
	end)

	if success then
		print("succesfully saved data of " .. plr.Name)
	else
		warn(response)
	end
end)

1 is not a valid member of DataStore “DataStoreService.SaveData”

1 Like
-- code before...
    local dataofuser = SaveData:GetAsync(plr.UserId)
    if dataofuser ~= nil then -- anything but nil
		print("Found data for " .. plr.Name)
		BoolValue.Value = SaveData[1]
	else
		print("Replacing no data with new data.")
		BoolValue = false
	end
-- code after...

SaveData itself can’t be indexed. Did you mean to write dataofuser[1]?

1 Like

idk maybe coz in 48 line error!