Hey! im trying to make a script in which if you buy a tool (with in-game coins) then you get a tool that will be in ur invetory forever so you don’t have to buy it everytime u rejoin.
save it to their datastore (like a value that this person has this gamepass), or check if this person has that gamepass upon joining
How would i do that? (i suck at scripting sry)
Here are some tutorials I found around YouTube, Follow these steps and you will be able to save tools.
Both are from popular Roblox Studio youtube creators!
I would start by creating a folder in ReplicatedStorage named Tools which will contain all of the available tools, and a script in ServerScriptService.
The code to put is below! By simply calling the AddTool function, it clones that tool inside of the specified player & saves it into a DataStore so that it’s there forever.
The first argument of the function should be the tool’s name and the second argument should be the player object.
Example | AddTool(“Sword”, game.Players.Someone)
Code
local ds = game:GetService("DataStoreService"):GetDataStore("tools")
local toolsfolder = game.ReplicatedStorage.Tools
local temp = {}
function AddTool(tool_name,player_instance)
if temp[player_instance.UserId] ~= nil then
table.insert(temp[player_instance.UserId],tool_name)
if toolsfolder:FindFirstChild(tool_name) then
local newitem = toolsfolder[tool_name]:Clone()
newitem.Parent = player_instance.Backpack
else
warn("Tool not found in the folder!")
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
local data = ds:GetAsync(plr.UserId)
if data ~= nil then
for i,v in pairs(data) do
if toolsfolder:FindFirstChild(v) then
local newitem = toolsfolder[v]:Clone()
repeat
wait(0.01)
until plr:FindFirstChild("Backpack")
wait(0.05)
newitem.Parent = plr.Backpack
else
warn("Tool not found in the folder!")
end
end
temp[plr.UserId] = data
else
temp[plr.UserId] = {}
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
if temp[plr.UserId] ~= nil then
ds:SetAsync(plr.UserId,temp[plr.UserId])
end
end)
If you have any questions or feedback, feel free to reply !
not in replicated storage, that would make it accessible with local scripts, which can be injected
a folder which server storage clones into would work though
They can change the location of the folder in the script by modifying the “toolsfolder” variable.