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

Is there such thing as GUI.Touched?

I am working on a game like among us, it is in gui form, is there any way I can detect if the player gui touches a wall or something? I can keep the player in a certain area, but if there is an object within that area, they can go right through it. Here is my current script: (There are other copies that are for different keys)

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local keydown = false



UIS.InputBegan:Connect(function(Input)
	
	if Input.KeyCode == Enum.KeyCode.W then
		keydown = true
	end
end)

UIS.InputEnded:Connect(function(Input)
	if Input.KeyCode == Enum.KeyCode.W then
		keydown = false
	end
end)

while true do
	wait()
	if keydown then
		if script.Parent.Parent.Floor.AbsolutePosition.Y > 302 then
			
		else
			--script.Parent.Position = script.Parent.Position - UDim2.new(0,0,0.005,0)
			script.Parent.Parent.Floor.Position = script.Parent.Parent.Floor.Position + UDim2.new(0,0,0.01,0)
		end	
	end
end

Thanks, is there any function that would help me that I should be aware of?

2 comments

0

Have you tried going through the events list under GuiObject to see if the is a function or event with a name like you Touched?

0

There is none. I did see a dev forum post that I am going to try though.

1 answer

Got this function from this Roblox Gear:

function Touching(a,b)
	local ap = Vector2.new(a.Position.X.Offset, a.Position.Y.Offset)
	local as = Vector2.new(a.Size.X.Offset, a.Size.Y.Offset)
	local bp = Vector2.new(b.Position.X.Offset, b.Position.Y.Offset)
	local bs = Vector2.new(b.Size.X.Offset, b.Size.Y.Offset)
	local c = (ap.x + as.x > bp.x) and (bp.x + bs.x > ap.x) and (ap.y + as.y > bp.y) and (bp.y + bs.y > ap.y)
	if c then
		return true
	else
		return false
	end
end 

to check just do if Touching(GuiObject1,GuiObject2) then

But it isn't that good yet, as It doesn't take rotation into account and you have to check collision between objects one by one. You can use the event guiObject:GetPropertyChanged("Position") and check Touching() on every otherGUI to make something like a Touched event.

5 comments

0

GUI.Touched is not a thing I don't believ.e

0

I will try this, thanks for yoir time!

0

@Nicholas1088 it is not, this is a function that is running with the name Touching.

0

Darn, did not work, just resulted with false every time they collided. Would it be because it is a local script?

0

I think you tried to use it as an event (button.Touching:connect()) but instead you have to use it as check statement (if Touching(GUIobj1,GUIobj2) == true then end),

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