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

What's wrong with this script? finding the greatest value

Asked by 9 years ago
hotscreen=script.Parent.hotscreen
uglyscreen=script.Parent.uglyscreen
while wait() do
    for i,v in pairs(game.Players:children()) do
        for i,v2 in pairs(v:children()) do
            for i,v3 in pairs(v:children()) do
            if v2.className=="NumberValue" then
                if v3.className=="NumberValue" then
                a=math.max(v2.Value)
                b=math.min(v3.Value)
                hotscreen.Image="http://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&Format=Png&username="..a.Parent.Name
                uglyscreen.Image="http://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&Format=Png&username="..b.Parent.Name
                end end
            end
        end
    end
end
0
I know it's wrong because I'm using .Parent on a property. I don't know how to fix that so.. help? SugarRushTheory 0 — 9y
0
put it in a code block please. XToonLinkX123 580 — 9y
0
Oh sorry SugarRushTheory 0 — 9y
0
my studio doesn't crash SugarRushTheory 0 — 9y
View all comments (7 more)
0
10:09:19.159 - Workspace.Part.SurfaceGui.Script:11: attempt to index global 'a' (a number value) SugarRushTheory 0 — 9y
0
Its because a is a value you can't found the parent of a value.. XToonLinkX123 580 — 9y
0
I said I know that's the problem, but I have no clue how to fix it. SugarRushTheory 0 — 9y
0
The part"a.Parent.Name"Its then player name ? XToonLinkX123 580 — 9y
0
Yeah, that's supposed to be the player name SugarRushTheory 0 — 9y
0
See at my awnser and tell me if its work.. XToonLinkX123 580 — 9y
0
Why did someone vote this down? the heck? SugarRushTheory 0 — 9y

1 answer

Log in to vote
4
Answered by 9 years ago

put your surfacegui in the workspace in the part. put the code in a serverscript

your code here:

local hotscreen = script.Parent.hotscreen
local uglyscreen = script.Parent.uglyscreen

local biggestValue = {}
local lowerValue = {}

game.Players.PlayerAdded:connect(function(player)
    local value = Instance.new("NumberValue",player)
    value.Name = "point"
end)


function Max(numbers)
    local last = {}
    while #numbers ~= 1 do
        wait()
        for index, value in pairs(numbers) do
            if type(value) == "number" then
                if numbers[index] and numbers[index + 1] and numbers[index] >= numbers[index + 1] then
                    table.remove(numbers, index + 1)
                elseif numbers[index] and numbers[index - 1] and numbers[index] >= numbers[index - 1] then
                    table.remove(numbers, index - 1)
                end
            else
                error("number unexpected !")
            end
        end
    end
    return tonumber(table.concat(numbers))
end

function Min(numbers)
    local last = {}
    while #numbers ~= 1 do
        wait()
        for index, value in pairs(numbers) do
            if type(value) == "number" then
                if numbers[index] and numbers[index + 1] and numbers[index] <= numbers[index + 1] then
                    table.remove(numbers, index + 1)
                elseif numbers[index] and numbers[index - 1] and numbers[index] <= numbers[index - 1] then
                    table.remove(numbers, index - 1)
                end
            else
                error("Number unexpected !")
            end
        end
    end
    return tonumber(table.concat(numbers))
end

while wait() do
    for i, v in pairs(game.Players:GetChildren()) do
        if v:IsA("Player") then
            biggestValue[i] = v:WaitForChild("point").Value
            lowerValue[i] = v:WaitForChild("point").Value
        end
    end
    for _, player in pairs(game.Players:GetChildren()) do
        if player:WaitForChild("point").Value == Max(biggestValue) then
            print(player.Name)
            hotscreen.Image = ("http://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&Format=Png&username="..player.Name)
        elseif player:WaitForChild("point").Value == Min(lowerValue) then
            print(player.Name)
            uglyscreen.Image = ("http://www.roblox.com/Thumbs/Avatar.ashx?x=200&y=200&Format=Png&username="..player.Name)
        end
    end
end
0
Wow thanks! SugarRushTheory 0 — 9y
0
You're welcome ! XToonLinkX123 580 — 9y
Ad

Answer this question