Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make Frames impossible to pass through?

Asked by
p0vd 207 Moderation Voter
4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
thank you for an actual answer. p0vd 207 — 4y
0
This confused me at first, but i now understand it. p0vd 207 — 4y
0
Sorry. Explaining stuff isnt my specialty. Glad it was of some use. XxTrueDemonxX 362 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

0
This is a ScreenGui. p0vd 207 — 4y
0
local position2 = game.Players.LocalPlayer.PlayerGui.ScreenGui.ImageLabel p0vd 207 — 4y
0
Oh I see, nevermind thing RobloxGameingStudios 145 — 4y
Log in to vote
0
Answered by
p0vd 207 Moderation Voter
4 years ago

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

Log in to vote
-1
Answered by 4 years ago

You can make an if script that won't let you move if you pass a certain position.

0
bruh Psudar 882 — 4y
0
... p0vd 207 — 4y
0
This doesn't help at all... p0vd 207 — 4y
0
wth RobloxGameingStudios 145 — 4y

Answer this question