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

How do I make Frames impossible to pass through?

This might not make sense, but i've made a LocalScript that basically makes an ImageLabel controllable by the player. (Using WASD) What I need is a script that makes a Frame (ImageLabel, etc.) impossible to pass through. For example, you cannot go past the left side of the screen in Super Mario Bros. Here is the code:

wait(0.1)
local runservice = game:GetService("RunService")
local position2 = game.Players.LocalPlayer.PlayerGui.ScreenGui.ImageLabel
runservice.RenderStepped:connect(function()
	if script.Up.Value == true then
		position2.Left.Disabled = true
		position2.Right.Disabled = true
		position2.Down.Disabled = true
		position2.Up.Disabled = false
		position2.Position = position2.Position + UDim2.new(0,0,-0.0025,0)
	end
	if script.Down.Value == true then
		position2.Left.Disabled = true
		position2.Right.Disabled = true
		position2.Down.Disabled = false
		position2.Up.Disabled = true
		position2.Position = position2.Position + UDim2.new(0,0,0.0025,0)
	end
	if script.Right.Value == true then
		position2.Left.Disabled = true
		position2.Right.Disabled = false
		position2.Down.Disabled = true
		position2.Up.Disabled = true
		position2.Position = position2.Position + UDim2.new(0.0025,0,0,0)
	end
	if script.Left.Value == true then
		position2.Left.Disabled = false
		position2.Right.Disabled = true
		position2.Down.Disabled = true
		position2.Up.Disabled = true
		position2.Position = position2.Position + UDim2.new(-0.0025,0,0,0)
	end
end)

Here is the game if more info is needed: https://www.roblox.com/games/3481420494/frisk-moving-test

4 answers

✓ Accepted answer

I see what you're attempting to do. I've tried something similar to this myself a while back. Essentially, before the actual movement you need to check that you won't surpass a certain point. This is a quickly whipped up example that should suffice for what you're trying to do using your left as an example:

if script.Left.Value == true and (position2.Position.X.Scale - .0025) > 0 then
	position2.Left.Disabled = false
	position2.Right.Disabled = true
	position2.Down.Disabled = true
	position2.Up.Disabled = true
	position2.Position = position2.Position + UDim2.new(-0.0025,0,0,0)
end

In the case of trickier values such as down:

if script.Down.Value == true and (position2.Position.Y.Scale + .0025) < ((frame's size) - (the image label's X scale size))
--rest of your down code here

So in the case of down and right which don't end on 0, you'll want what the frame's size is and subtract the size of the frame that it's in by your imagelabel's scale so that it can never surpass the edge of your right side + imagelabel's size.

Kinda hard for me to properly explain without showing a direct demonstration but I hope you understand and that this helps solve your issue.

3 comments

0

thank you for an actual answer.

0

This confused me at first, but i now understand it.

0

Sorry. Explaining stuff isnt my specialty. Glad it was of some use.

This makes no sense. If a frame is on a surface gui which is on a part, then simply change the CanCollide value in the part to true, problem solved.

3 comments

0

This is a ScreenGui.

0

local position2 = game.Players.LocalPlayer.PlayerGui.ScreenGui.ImageLabel

0

Oh I see, nevermind thing

It seems like no one knows or how to script this. I might delete this soon.

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