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

How can I make a script check for a specific value of a player on a leaderboard?

Asked by 5 years ago
Edited 5 years ago

I am finishing up with my game and I want to add a feature that when a player touches a block, it will check if it has, lets say, 2 kills on the leaderboard before teleporting them somewhere. The the only thing I need help with is the script checking the leaderboard for the player's points. How would I go about making this? This is what I have so far:

local PointsService = game:GetService('PointsService')

function onTouched(part) 
local h = part.Parent:findFirstChild("Humanoid") 
if h ~= nil then

script.Parent.Touched:connect(onTouched)

function 
    if h 
end

3 answers

Log in to vote
0
Answered by
danglt 185
5 years ago
local PointsService = game:GetService('PointsService')

function onTouched(part) 
local h = part.Parent:findFirstChild("Humanoid") 
if h ~= nil then

script.Parent.Touched:connect(onTouched)

function 
    if (point to leaderstats).Kills == 2 then
(teleport stuff)
end

If this helped accept awnser!

Ad
Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago

I usually like to wire a debounce to each player that touches the brick, rather than make the whole server conform to the same debounce.

local touchers = {}
local requiredKills = 2
local debouncetime = .5

local function debounce(player)
    local lasttimetouched = debouncetime
    local playerintable = touchers[player.Name]
    -- has the player touched the brick before?
    if playerintable then 
        lasttimetouched = tick() - touchers[player.Name]
        -- check the last time we touched it in seconds
        if lasttimetouched >= debouncetime then 
            -- if we surpassed the required debounce time
            -- reset the last time we touched it
            touchers[player.Name] = tick()
        end
    else
        -- New player touched it, index them.
        touchers[player.Name] = tick()
    end
    return lasttimetouched >= debouncetime, lasttimetouched
end

script.Parent.Touched:Connect(function(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent)
    -- Get player from the limb that hit our brick
    if player and player.Character.Humanoid.Health > 0 then 
        -- it was a player and they're not dead
        local debounce, timelasttouched = debounce(player)
        -- check to see if we can touch the brick
        if debounce then
            local stats = player:findFirstChild("leaderstats")
            -- find their stats folder
            local kills = stats and stats:findFirstChild("Kills")
            -- find the stat
            if kills then 
                if kills.Value >= requiredKills then 
                    -- do something
                else
                    local difference = requiredKills - kills.Value 
                    local plural = difference > 1 and "s" or ''
                    print( string.format ( "You need %s more kill%s to do that", difference, plural) )
                end
            else
                print("can't find stats")
            end
        else
            print(timelasttouched)
        end
    end
end)
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago
local PointsService = game:GetService('PointsService')

function onTeleport(char)
    --Teleport script
end
function onTouched(part) 
    local h = part.Parent:findFirstChild("Humanoid") 
    if h then
        local plr = game:GetService("Players"):GetPlayerFromCharacter(part.Parent)--I got plr
        if plr:FindFirstChild("leaderstats").kills.Value >= 2 then
            onTeleport(hit.Part)--function onTeleport script and sent character(hit.Part)
        end
    end
end


script.Parent.Touched:connect(onTouched)

--[[function
    if h 
end
I have no idea what this is.
--]]

I made a onTeleport function and I have no idea what function at the bottom is. I put that in comments.

Answer this question