Answered by
4 years ago Edited 4 years ago
This script was taken from a youtuber's video. You're most likely getting errors because you didn't modify the script and instead just copied and pasted it with a little name change.
Also to note, you should ALWAYS check server-side, never trust the client. Exploiters can easily spoof the client.
The first script is unecessary, that is what is most likely causing the duplication of tools. StarterGear
is what tools the player will spawn with. When player respawns with a tool in their StarterGear they get their tool back, you also clone the same tool to their backpack thus making 2 copies of that tool.
01 | local DSS = game:GetService( "DataStoreService" ) |
02 | local DataStore = DSS:GetDataStore( "YourDataStoreHere" ) |
03 | local toolStorage = game:GetService( "ServerStorage" ):WaitForChild( "ShopTools" ) |
05 | local function onPlayerAdded(Player) |
07 | local suc,err = pcall ( function () |
08 | Data = DataStore:GetAsync(Player.UserId) |
16 | for _,v in pairs (Data) do |
17 | for _,t in pairs (toolStorage:GetChildren()) do |
19 | t:Clone().Parent = Player.StarterGear |
20 | if not Player.Backpack:FindFirstChild( "t.Name" ) then |
21 | t:Clone().Parent = Player.Backpack |
27 | if not Player.Backpack:FindFirstChild( "TheTool" ) then |
28 | toolStorage.TheTool:Clone().Parent = Player.Backpack |
29 | toolStorage.TheTool:Clone().Parent = Player.StarterGear |
34 | local function onPlayerRemoved(Player) |
36 | for _,v in pairs (Player.StarterGear:GetChildren()) do |
37 | table.insert(DataToSave, v.name) |
39 | local suc,err = pcall ( function () |
40 | DataStore:SetAsync(Player.UserId, DataToSave) |
44 | game:GetService( "Players" ).PlayerAdded:Connect(onPlayerAdded) |
45 | game:GetService( "Players" ).PlayerRemoving:Connect(onPlayerRemoved) |
47 | game:BindToClose( function () |
48 | for _,Player in pairs (game:GetService( "Players" ):GetPlayers()) do |
49 | onPlayerRemoved(Player) |
The script you provided had a lot of deprecated functions which I had to replace.
I'm sorry if this didn't work. I rushly typed this so comment on this answer if you're receiving errors and I'll happily help you.