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

How would I check which gui is at a certain position?

PROBLEM IN SCRIPT

	for i, v in pairs(script.Parent.Parent.SpinningFrame:GetChildren()) do
		if v.Position.X.Scale == 10.333 then
			print(v.TextLabel.Text .. "is the winner!")
		end
	end

I made a crate opening system which works fine, but now I need to figure out which one is the item that is being won, (winning item is at 10.333,0,0,0). Since I don't know how to do gui collision, I tried this but for some reason it doesnt work? It doesnt print, and theres no errors.

WHOLE SCRIPT

--[[ Debounce ]]--
local click = false
--[[ Click ]]--
script.Parent.MouseButton1Click:connect(function()
	--[[ Debounce ]]--
	if click == false then
	click = true
	
	--[[ Sound ]]--
	script.Parent.Parent.Sound:Play()
	script.Parent.Text = "Opening!"
	
	--[[ Loop ]]--
	for i = 1,90, 1 do

	script.Parent.Parent["SpinningFrame"]:TweenPosition(UDim2.new(-10,0,0.25,0),"Out","Linear",8.75,false)
	
	--[[ Random ]]--
	local random = math.random(1,100)
	local string = ""	
	
	local clone = script.Parent.Parent.Copy:Clone()
	clone.Parent = script.Parent.Parent.SpinningFrame
	
	if random >= 1 and random < 3 then
	string = "Legendary"
	script.Parent.Parent.LEGENDARY:Clone().Parent = clone.TextLabel
	clone.TextLabel.LEGENDARY.Disabled = false
	elseif random >= 3 and random < 23 then
	string = "Epic"
	clone.TextLabel.TextColor3 = Color3.fromRGB(170,0,255)
	elseif random >= 23 and random < 50 then
	string = "Rare"
	clone.TextLabel.TextColor3 = Color3.fromRGB(255, 170, 0)
	elseif random >= 50 and random <= 100 then
	string = "Common"
	clone.TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
	end	
	
	clone.TextLabel.Text = string
	clone.Position = UDim2.new(-2 + i / 3,0,0,0)
	wait(.1)
	end
	--[[ Finished ]]--
	local item = ""
	for i, v in pairs(script.Parent.Parent.SpinningFrame:GetChildren()) do
		if v.Position.X.Scale == 10.333 then
			print(v .. "is the winner!")
		end
	end
	
	script.Parent.Parent["SpinningFrame"]:TweenPosition(UDim2.new(-10,0,0.25,0),"Out","Linear",.1,true)
	script.Parent.Text = "Congratulations!"
	print(item)
	wait(2.5)
	script.Parent.Text = "Please Wait..."
	script.Parent.Parent.SpinningFrame.Position = UDim2.new(4,0,.25,0)
	script.Parent.Parent.SpinningFrame:ClearAllChildren()
	wait(2.5)
	print('Finished')
	click = false
	script.Parent.Text = "Open Crate!"
	end
end)

3 comments

0

The only green is the comments not sure why under it is green.

0

I rather do this since Im still new to getchildren and if i do gui collision im going to have to use getchildren also for what im doing.

1 answer

If v's position is equal to UDim2.new(10.333, 0, 0, 0), then let's print correct.

for i, v in pairs(script.Parent.Parent.SpinningFrame:GetChildren()) do
	v.Changed:connect(function()
    		if v.Position.X.Scale == 10.333 then
			print(v.TextLabel.Text .. "is the winner!")
		end
	end)
end

Also, 0.333 sounds like a reccuring number. Be careful

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