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

I need my script fixed BACKPACK 'data?'

Asked by 4 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

https://web.roblox.com/library/5872123105/Please-fix-this-script

So there's leaderstats where every 2 seconds the player gets 100 'minutes' (i'm just testing with it) which works. There's a keycard that the player gets after 300 'minutes' of the leaderstats. (which works.) But when the player resets/dies the item is removed from the inventory (backpack) which I don't want, I want the gear to STAY within the inventory. And the player can't get the item back because it's already been over '300' so I need help with that... Sorry if this sounds confusing, I can explain more sort of.

0
Put the script here Gey4Jesus69 2705 — 4y
0
local KeyCard = game.ServerStorage["KeyCard"] game.Players.PlayerAdded:Connect(function(plr) while wait(1) do if plr:WaitForChild("leaderstats"):FindFirstChild("Minutes").Value >= 300 then KeyCard:Clone().Parent = plr:WaitForChild("Backpack") break end end end) ToastyXoYT 5 — 4y
0
The script, keycard is in the model link ToastyXoYT 5 — 4y
0
You may require a backpack saver RazzyPlayz 497 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Well, it looks like you are giving the Keycard to the player, when the player join and then breaking the loop when the requirements are met. There is a CharacterAdded event, which fires on character respawn :

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        repeat wait() until char -- Waits until full character is loaded    

        -- The code
    end)
end)

So, to simplify your code, you can make it a function and execute it on character respawn.

function GiveKeycard(plr)
    local KeyCard = game.ServerStorage["KeyCard"]

    while wait(1) do 
        if plr:WaitForChild("leaderstats"):FindFirstChild("Minutes").Value >= 300 then 
            KeyCard:Clone().Parent = plr:WaitForChild("Backpack") 
            break 
        end 
    end 
end

Now, you can fire the function on PlayerRespawn :

function GiveKeycard(plr)
    local KeyCard = game.ServerStorage["KeyCard"]

    while wait(1) do 
        if plr:WaitForChild("leaderstats"):FindFirstChild("Minutes").Value >= 300 then 
            KeyCard:Clone().Parent = plr:WaitForChild("Backpack") 
            break 
        end 
    end 
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        repeat wait() until char -- Waits until full character is loaded    
        GiveKeyCard(player)
    end)
end)

Lemme know if it helps!

Ad

Answer this question