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

Playerpoints on join when players kills load?

Asked by
DanzLua 2879 Moderation Voter Community Moderator
9 years ago

Hey! I'm using the script below to give people playerpoints every time they kill someone, the problem is that i also have a script that loads there kills when they join the game, so when they join the game and they get there kills back they also get playerpoints. anybody know how to fix this, thx.

the script that gives them the playerpoints.

local ps = game:GetService("PointsService")
game.Players.PlayerAdded:connect(function(player)
    local leaderstats = player:WaitForChild("leaderstats")
    local kos = leaderstats:WaitForChild("KOs")
    kos.Changed:connect(function()
        if ps:GetAwardablePoints() >= script.PlayerPoints.Value and kos.Value%script.Kills.Value == 0 then
            ps:AwardPoints(player.userId,script.PlayerPoints.Value)
        end
    end)
end)

the script that loads the kills.

local Chat = true
local Messages = true
local Normal = true
local Obby = false
local BestFriends = false
local Friends = false
local OwnerOnly = false
local Gamepass = false --[[ ---> ]] GamepassID = "" -- Gamepass ID
local Item = false --[[ ---> ]] ItemID = "" -- Item ID
local List = false --[[ ---> ]] NameList = {"Ex1", "Ex2"} -- Names

function SendMessage(Txt, player)
    if Messages then
        local Hint = Instance.new("StringValue", player.PlayerGui)
        Hint.Value = "Your stats have been loaded." Hint.Name = "AutoSaverCommand"
        local HintScript = script:WaitForChild("SendingHints"):clone()
        HintScript.Parent = player.PlayerGui HintScript.Disabled = false
        wait(0.70)
        Hint:Destroy()
    end
end

function Load(player)
    local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
    local stats = player:FindFirstChild("leaderstats"):GetChildren()
    for i = 1, #stats do            
        stats[i].Value = datastore:GetAsync(stats[i].Name)
    end
    SendMessage("Your stats have been loaded.", player)
end

function Save(player)
    local datastore = game:GetService("DataStoreService"):GetDataStore(player.Name.."Stats")
    local statstorage = player:WaitForChild("leaderstats"):GetChildren()
    for i =  1, #statstorage do
        datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
    end
    SendMessage("Your stats have been saved.", player)
end

function Decide(player, leaving)
    if leaving then
        Save(player)
    else
        Load(player)
    end
end

function DoObby(player)
    Decide(player, leaving)
    repeat wait() until player.leaderstats and player.Camera and player.Character
    player:LoadCharacter(true)
end

function OwnsAsset(player, gamepass, leaving)
    if gamepass then
        if game:GetService('GamePassService'):PlayerHasPass(player, GamepassID) then
            Decide(player, leaving)
        end
    elseif game:GetService('MarketplaceService'):PlayerOwnsAsset(player, ItemID) then
        Decide(player, leaving)
    end
end

function DoOptions(player, leaving)
    if Obby then
        DoObby(player)
    elseif OwnerOnly then
        if player.userId == game.CreatorId then
            Decide(player, leaving)
        end
    elseif Friends then
        if player:IsFriendsWith(game.CreatorId) then
            Decide(player, leaving)
        end
    elseif BestFriends then
        if player:IsBestFriendsWith(game.CreatorId) then
            Decide(player, leaving)
        end
    elseif List then
        for i, v in pairs(NameList) do
            if player.Name == v then
                Decide(player, leaving)
            end
        end
    elseif Gamepass then
        OwnsAsset(player, true, leaving)
    elseif Item then
        OwnsAsset(player, false, leaving)
    end
end

function getSpecific(player, leaving)
    if leaving and Normal then
        Save(player)
    elseif not leaving and Normal then
        Load(player)
    elseif not Normal then
        DoOptions(player)
    end
end

game.Players.PlayerRemoving:connect(function(player)
    getSpecific(player, true)
end)

game.Players.PlayerAdded:connect(function(player)
    for k = 1, 60, 0.03 do
        wait()
        if player:findFirstChild("leaderstats") then
            getSpecific(player, false)
            break
        end
    end
    player.Chatted:connect(function(c)
        if Chat then
            if c:lower() == "/save" or c:lower() == "/ save" then
                getSpecific(player, true)
            --[[

            elseif c:lower() == "/load" or c:lower() == "/load" then
                getSpecific(player, false)

            --]]

            -- [ @Above, OPTIONAL. ] --
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by 9 years ago
local pointsAwarded = 10 -- Change to what you want to be awarded

game.Players.PlayerAdded:connect(function(player)
    if game.PointsService:GetAwardablePoints() >= pointsAwarded then
        game.PointsService:AwardPoints(player.UserId, pointsAwarded)
    end
end)
0
That should award points to the player when they enter the game. ObscureEntity 294 — 9y
0
I don't want this to happen, the player points are given when there kills load @sweetpea11fir DanzLua 2879 — 9y
0
So it depends on how many kills they have? And the title to this said "Player Points when Player Joins" so... ObscureEntity 294 — 9y
0
the title is "player points when player's "Kills load"" @seetpea11fir the script give the playerpoints to the players when they join cause there kills load DanzLua 2879 — 9y
Ad

Answer this question