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

Trying To Make ToolSave Not Dupe Tools AND Making Tool Check?

Asked by 4 years ago

The Title Is Confusing IK Buuuutt i will try to explain it

The First Script im making is a script to save tools and when you reset it duplicates the basic starter tool, so i want it to not dupe and i have tried an IF statement shown here:

01char.Humanoid.Died:connect(function()
02            char.Humanoid:UnequipTools()
03            if player.Backpack:WaitForChild("Basic Halo") == true
04            then
05                print("Already Has Basic")
06                else
07        local old = player.StarterGear:GetChildren()
08        for i = 1, #old do
09            old[i]:Destroy()
10        end
11 
12        local new = player.Backpack:GetChildren()
13        for i = 1, #new do
14            new[i].Parent = player.StarterGear
15        end    
16            end
17            end)   

Second Script: the second one is a local script to check if the player has the Molten Halo Tool when joining if the player does it will not give them the starter halo....

ToolSave Script (Normal Script, Server Script Service)

001local ds = game:GetService("DataStoreService")
002local store = ds:GetDataStore("saveStore")
003local library = game:GetService("ServerStorage").ShopItems
004 
005--< directory functions
006 
007local dir = {}
008 
009local function edit(player, list)
010    dir[player.Name] = list
011end
012 
013local function setup(player, list)
014    for i = 1, #list do
015        local tool = library:FindFirstChild(list[i])
View all 124 lines...

the local script to check if the player has the tool:

01local player = game.Players.LocalPlayer
02 
03function checkBasic()
04    wait(0.6)
05    if player.Backpack:GetFirstChild("Molten Halo") == true
06        then
07        player.Backpack:GetFirstChild("Basic Halo"):Destroy()
08        end
09    end
10 
11game.Players.ChildAdded:Connect(checkBasic)

Thanks Joe.

1 answer

Log in to vote
0
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.

01local DSS = game:GetService("DataStoreService")
02local DataStore = DSS:GetDataStore("YourDataStoreHere")
03local toolStorage = game:GetService("ServerStorage"):WaitForChild("ShopTools") --The folder might not be loaded it so we use WaitForChild just in case
04 
05local function onPlayerAdded(Player)
06    local Data
07    local suc,err = pcall(function() --Make a pcall function
08        Data = DataStore:GetAsync(Player.UserId)
09    end)
10    if suc then
11        print("Success!") --If the pcall was a success we let the server know
12    else
13        print("Error!") --If the pcall was erroring we let the server know
14    end
15    if Data then --If the player has tools saved then
View all 51 lines...

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.

Ad

Answer this question