Hello, I was wondering how I could make a NPC sell a tool when you click its torso. So far I have a script for DataStore / Money leaderboard.
------Here is what my Game Explorer Looks like https://gyazo.com/488bdcd1f297e1beb22d9c072f8c2458
-- How to save data in your Roblox game
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Parent = leaderstats
cash.Value = 450
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserID.."-cash")
end)
if success then
cash.Value = data
else
print("There was an error whilest getting your data")
wait(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore:SetAsync(player.UserID.."-cash",player.leaderstats.Cash.value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error when saving data")
warn(errormessage)
end
end)

1 comment
You wanna sell NPCs or Tools?