Everything is fine and it says bought, but if you leave and rejoin, you still have the tool, but it says buy and you can buy it again, How do I make it to where it stays bought even when you rejoin? Heres the buy script-
local player = game.Players.LocalPlayer local rs = game:GetService("ReplicatedStorage") local tool = rs:WaitForChild("Chicken") local stats = player:WaitForChild("leaderstats") local button = script.Parent cost = 200 script.Parent.MouseButton1Click:Connect(function() script.Parent.Text = 'ItemOwned' game.ReplicatedStorage.Events.Event1:FireServer(100) if stats.Pounds.Value < cost then script.Parent.Text = 'Need More Money' wait(1) script.Parent.Text = 'Buy Chicken - 200 Pounds' end end)
Here is the RemoteEvent Script-
local tools = game.ReplicatedStorage:WaitForChild("Chicken") game.ReplicatedStorage.Events.Event1.OnServerEvent:Connect(function(player,tool) local stats = player:FindFirstChild("leaderstats") if stats.Pounds.Value >= 200 then stats.Pounds.Value = stats.Pounds.Value - 200 game.StarterGui:WaitForChild("Mobile/Desktop Gui1"):WaitForChild("ShopGUI"):WaitForChild("Frame"):WaitForChild("Item2").Text = "ItemOwned" game.StarterGui:WaitForChild("Mobile/Desktop Gui1"):WaitForChild("ShopGUI1"):WaitForChild("Frame"):WaitForChild("Item2").Text = "ItemOwned" local clone = tools:Clone(tool) clone.Parent = player.Backpack local clone2 = tools:Clone(tool) clone2.Parent = player.StarterGear script:Destroy() end end)
Here is the tool datastore script-
local RunService = game:GetService("RunService") local ToolData = game:GetService("DataStoreService"):GetDataStore("ToolData") local ToolLocation = game.ServerStorage.Tools -- The location where all your tools are saved function GetToolByName(toolName) for _, tool in pairs(ToolLocation:GetChildren()) do if tool.Name == toolName then return tool end end end function IsRegisteredTool(tool) for _, playerTool in pairs(ToolLocation:GetChildren()) do if playerTool.Name == tool.Name then return true end end end game.Players.PlayerAdded:Connect(function(player) repeat wait() until player.Character local dataKey = "tool-data_"..player.UserId if ToolData:GetAsync(dataKey) then for i, toolName in pairs(ToolData:GetAsync(dataKey)) do local newStarterTool = GetToolByName(ToolData:GetAsync(dataKey)[i]):Clone() local newTempTool = GetToolByName(ToolData:GetAsync(dataKey)[i]):Clone() newStarterTool.Parent = player.StarterGear newTempTool.Parent = player.Backpack end ToolData:SetAsync(dataKey, {}) end end) game.Players.PlayerRemoving:Connect(function(player) local dataKey = "tool-data_"..player.UserId local playerTools = {} for _, tool in pairs(player.StarterGear:GetChildren()) do if tool:IsA("Tool") and IsRegisteredTool(tool) then table.insert(playerTools, 1, tool.Name) end end if RunService:IsStudio() or #playerTools < 1 then return end ToolData:SetAsync(dataKey, playerTools) end)
All what you need to do is check if the player already the item. To do that, just use condition:
local player = game.Players.LocalPlayer local rs = game:GetService("ReplicatedStorage") local tool = rs:WaitForChild("Chicken") local stats = player:WaitForChild("leaderstats") local button = script.Parent cost = 200 -- this condiditon show "bought" if player already the item without pressing the button to check it. if local item = player.Backpack:FindFirstChild(tool.Name) then script.Parent.Text = "Bought" end script.Parent.MouseButton1Click:Connect(function() if player.Backpack:FindFirstChild(tool.Name) then -- if "Chicken" is in the Backpack then.. script.Parent.Text = "Bought" else -- if player doesnt have chicken, allow him to buy one. game.ReplicatedStorage.Events.Event1:FireServer(100) if stats.Pounds.Value < cost then script.Parent.Text = 'Need More Money' wait(1) script.Parent.Text = 'Buy Chicken - 200 Pounds' end end end)