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

Is this on ROBLOX's end or can I fix this?

Though no errors appear, it is simply not printing what I need it to. Full script:

local b = script.Parent
local screen = b.Parent.Screen
local hats = {["Euro 180"] = 401464679, ["Gold Ollie"] = 401464681, ["Red Grind"] = 401464684, ["Purple Indy"] = 401464683, ["Star Tailslide"] = 401464687}
local pose = {"Euro 180", "Gold Ollie", "Red Grind", "Purple Indy", "Star Tailslide"}
local db = false
local price = 100000

b.ClickDetector.MouseClick:connect(function(plr)
	if db == false then
		db = true
		if plr.leaderstats.Coins.Value >= price then
			plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - price
	for key, v in pairs(hats) do
	for i = .1, 4 do
		wait(.1)
		screen.item.Texture = "rbxassetid://"..hats[pose[math.random(1, #pose)]]
		end
	end
local num = screen.item.Texture:sub(14)
for key, v in pairs(hats) do
if num == hats[key] then
	print("Won a "..key.." // id="..v)
end
end
db = false
		end
		end
end)

Part not working:

local num = screen.item.Texture:sub(14)
for key, v in pairs(hats) do
if num == hats[key] then
	print("Won a "..key.." // id="..v)
end
end

1 answer

✓ Accepted answer

Logical equality
It's only logical

So, hats[key] is a number, but num is a string. Numbers aren't equal to strings, even if they technically represent the same value. You can solve this by either calling tostring on the value, or tonumber on the string. Your call.

local num = tonumber(screen.item.Texture:sub(14)) -- Once.
for key, v in pairs(hats) do
if num == v then -- hat[key] == v; redundant index
    print("Won a "..key.." // id="..v)
end
end

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