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

How to reward upon completiion of round?

Asked by 6 years ago

So I'm trying to reward xp upon completion of a game. However nothing is working, so I have no idea what im doing right/wrong. Can someone please explain this to me

RoundService

local roundtime = 15
local roundStopped = false
player = game.StarterPlayer.StarterPlayerScripts.Parent
local Humanoid = player:findFirstChild("Humanoid")
local tag = Humanoid:findFirstChild("creator") 
local leaderstats = tag.Value:findFirstChild("leaderstats") 

while true do
    print("Round starting...")
    for i = roundtime,0,-1 do
        if roundStopped then break end
        print(i.." seconds left")
        wait(1)
    end
    roundStopped = false
    print("Round finished")
end

workspace["RedKing"].Humanoid.Died:Connect(function()
    roundStopped = true
    leaderstats.Games.Value = leaderstats.Games.Value + 1
    leaderstats.XP.Value = leaderstats.XP.Value + 150
end)

workspace["BlueKing"].Humanoid.Died:Connect(function()
    roundStopped = true
    leaderstats.Games.Value = leaderstats.Games.Value + 1
    leaderstats.XP.Value = leaderstats.XP.Value + 150

end)

Leaderstats

game.Players.PlayerAdded:connect(function(Player)
    local leaderstats = Instance.new("IntValue",Player)
    leaderstats.Name = "leaderstats"
    local XP = Instance.new("IntValue",leaderstats)
    XP.Name = "XP" 
    XP.Value = 0
    local Level = Instance.new("IntValue",leaderstats)
    Level.Name = "Level" 
    Level.Value = 1 
    local Games = Instance.new("IntValue",leaderstats)
    Games.Value = 0
    Games.Name = "Games Played"

    XP.Changed:connect(function() XPChange(Player,XP,Level) end)

end)

function XPChange(Player,XP,Level) 
    if XP.Value >= Level.Value*150  then
        XP.Value = 0 
        Level.Value = Level.Value+ 1
    end
end

xp gain starterplayerscript

local Humanoid = script.Parent.Humanoid
function PwntX_X() 
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.XP.Value = leaderstats.XP.Value + 10
wait(0.1) 
script:remove()
            end 
        end 
    end 
end 
Humanoid.Died:connect(PwntX_X) 
0
Are you getting any errors? DevNetx 250 — 6y

Answer this question