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

Attempt to compare two userdata values; how would i get around this?

So, I'm trying to make a script that changes the text, which you can probably see, but I keep getting this error in the output that says that on line 17 "Attempt to compare two userdata values" Is there a way to get around this? Also, the values are all numbervalues. Here's my script

local pv = game:GetService("ReplicatedStorage").PointValues
local red = pv:WaitForChild("RedPoints")
local blue = pv:WaitForChild("BluePoints")
local green = pv:WaitForChild("GreenPoints")
local yellow = pv:WaitForChild("YellowPoints")

red.Changed:Connect(function()
	while wait() do
		if red > blue and red > green and red > yellow then --if red is winning
		script.Parent.Text = "Red Has the Most Points!"
		end
	end
end)

blue.Changed:Connect(function()
	while wait() do
		if blue > red and blue > green and blue > yellow then--if blue is winning
		script.Parent.Text = "Blue Has the Most Points!"
		end
	end
end)

green.Changed:Connect(function()
	while wait() do
		if green > red and green > blue and green > yellow then--if green is winning
		script.Parent.Text = "Green Has the Most Points!"
		end
	end
end)

yellow.Changed:Connect(function()
	while wait() do
		if yellow > red and yellow > blue and yellow > green then
			script.Parent.Text = "Yellow Has the Most Points!"--if yellow is winning
		end
	end
end)

2 comments

0

Are the colors (RedPoints, etc.) all IntValues?

0

They are all numbervalues

1 answer

✓ Accepted answer

The issue is you're comparing two NumberValues as the objects themselves. You need to compare their values. Luckily it's as simple as comparing both of their 'Value' properties, so change it to: if red.Value > blue.Value and red.Value > green.Value and red.Value > yellow.Value then And do similar changes to wherever you made that error again throughout the script.

1 comment

0

Thx for the help!

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