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

How can i make this much simpler?

Asked by 8 years ago
-- Script 1
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Swords = ReplicatedStorage:FindFirstChild('Swords')
game.Workspace.ChildAdded:connect(function(plr)
if plr:IsA("Player") then
local RewarableScript = script:WaitForChild('Rewardable')
RewarableScript:Clone().Parent = plr
plr:FindFirstChild('Rewardable').Disabled = false
end
end)

-- Script 2 
local Humanoid = script.Parent.Humanoid 
function Death() 
local tag = Humanoid:findFirstChild("creator") 
    if tag ~= nil then 
        if tag.Value ~= nil then 
local leaderstats = tag.Value:findFirstChild("leaderstats") 
if leaderstats ~= nil then 
leaderstats.Lvl.Value = leaderstats.Lvl.Value + 1
wait(0.1)
script:remove()
            end 
        end 
    end 
end 

Humanoid.Died:connect(Death) 

0
This is already pretty simple. Instead of just pasting your code, explain what you mean and what you need help with. Pyrondon 2089 — 8y

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

I don't know what you were trying to accomplish, so I just rewrote the format for you so you can do what you want with it:

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Swords = ReplicatedStorage:FindFirstChild('Swords')

game.Players.PlayerAdded:connect(function(Player)
    -- Everytime a player joins the game, set up these connections

    -- Create leaderstats here


    Player.CharacterAdded:connect(function(Character)
        -- Stuff you do every time the Player respawns


        Character:WaitForChild("Humanoid").Died:connect(function()
            -- Stuff you do every time the Player dies

            local tag = Humanoid:FindFirstChild("creator") 
            if tag and tag.Value then 
                local leaderstats = tag:FindFirstChild("leaderstats") 
                if leaderstats then
                    leaderstats.Lvl.Value = leaderstats.Lvl.Value + 1
                end
            end

        end)

    end)

end)
Ad

Answer this question