Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

11 comments

0

I know it's wrong because I'm using .Parent on a property. I don't know how to fix that so.. help?

0

put it in a code block please.

0

Oh sorry

0

my studio doesn't crash

0

10:09:19.159 - Workspace.Part.SurfaceGui.Script:11: attempt to index global 'a' (a number value)

0

Its because a is a value you can't found the parent of a value..

0

I said I know that's the problem, but I have no clue how to fix it.

0

The part"a.Parent.Name"Its then player name ?

0

Yeah, that's supposed to be the player name

0

See at my awnser and tell me if its work..

0

Why did someone vote this down? the heck?

1 answer

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

2 comments

0

Wow thanks!

0

You're welcome !

This discussion is preserved as it was. New answers, comments, and votes are closed.