Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Datastores tool saves help?

Asked by 7 years ago

Ok im making an RPG game and datapersistance is not reliable to save stuff constantly so i need to make a datastore that saves stuff. I know they cant save instances or tools directly but i need to save them in a table.

Can someone please make the base script for me where i can put in the sword names. I Will give credit to whoever makes it and they will have their name in my game aslong as they want it. PLEASE HELP ive been trying to do this all week and cant figure it out --Copyed from forums

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
7 years ago

The easiest way to do this is by having a folder that stores all the tools and simply saving the name of the tools that the player has. That way to can clone the tool from the folder using if you know its name and give it to the player.

Loading Tools:

local dataStore = game:GetService("DataStoreService"):GetDataStore("Tools")
local tools = game.ServerStorage.Tools

game.Players.PlayerAdded:connect(function()
    local key = player.userId
    local userTools = dataStore:GetAsync(key) -- Table of tool names
    for _, tool in ipairs(userTools) do
        tools[tool].Clone().Parent = player.StarterGear
    end
end)

function giveTool(toolName)
    local key = player.userId
    local userTools = dataStore:GetAsync(key)
    tools[toolName].Clone().Parent = player.StarterGear
    table.insert(userTools, toolName)
    dataStore:SetAsync(key, userTools)
end
Ad

Answer this question