Hey Developers! I am trying to get the green pad (shown in photo) to pull up a ScreenGui when you step on it and when you walk off it the menu goes away. Thanks!
Hello! I have some code that just might work! Insert this into a LocalScript
inside of your Gui in StarterGui:
local TouchPart = game.Workspace.TouchPart -- Change this to wherever the part you want to touch is parented to.
TouchPart.Touched:Connect(function()
script.Parent.YourGui.Visible = true --Change "YourGui" to whatever the GUI you want to appear is named.
end)
TouchPart.TouchEnded:Connect(function()
script.Parent.YourGui.Visible = false
end)
Hope this helps!
It didn’t work and I followed all the steps, I have enabled the screengui and tried and disabled it and it still doesn’t seem to work?
I would recommend looking at this topic, for some inspiration about the best way to go about doing this:
That post is old, you can probably use an implementation using the spatial query api
Or use zoneplus, spatial queries would be more of a headache
I’m surprised it didn’t work, because it worked perfectly for me. Although, your way makes more sense.
I don’t know if you have already found a solution but, if not here is my mini tutorial😆:
(Now I am not the best at scripting so I know there are probably better ways to make this)
-
Make your Ui and put it in
StarterGui
. Here is my Ui for demonstration purposes:
-
Once your done editing the frame, shirnk its size down [my frame is shrinked down to: (0.025,0)(0.025,0)].
Under the Ui frame, insert a local script and put this into it:
local Detector = game.Workspace:WaitForChild("Shop"):WaitForChild("detector") --Find the part that will open the shop
local CloseDistance = math.max(Detector.Size.X, Detector.Size.Z)
local CloseButton = script.Parent.Close --Close
local function tweenSize(object,goal,Time) --Make a tween function
local tween = game:GetService("TweenService"):Create(object,TweenInfo.new(Time,Enum.EasingStyle.Quad),{Size = goal}) --Create a tween
local db = false --Make a debounce
if not db then
db = true
tween:Play()
task.wait(Time+0.05) --Cool down time
db = false
end
return tween
end
Detector.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) == game.Players.LocalPlayer then
script.Parent.Parent.Enabled = true
tweenSize(script.Parent,UDim2.fromScale(0.5,0.5),.5) --Remember the parameters we put in the function above? Insert the object your tweening, the size it will tween to, and the length of the tween
end
end)
CloseButton.Activated:Connect(function() --A function for when the player clicks the close button
tweenSize(script.Parent,UDim2.fromScale(0.025,0.025),.5)
script.Parent.Parent.Enabled = false
end)
script.Parent.Parent.Enabled = false
script.Parent.Parent:GetPropertyChangedSignal("Enabled"):Connect(function() --A function to see if the player is inside the part
while script.Parent.Parent.Enabled do
task.wait(.05)
if game.Players.LocalPlayer.Character then
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local mag = (HumanoidRootPart.Position-Detector.Position).Magnitude
if mag >= CloseDistance + math.max(HumanoidRootPart.Size.X, HumanoidRootPart.Size.Z) and script.Parent.Parent.Enabled == true then
tweenSize(script.Parent,UDim2.fromScale(0.025,0.025),.5) --Change to the size you want it to shrink down to
script.Parent.Parent.Enabled = false
end
end
end
end)
- Test to see if it works
And here is the studio file:
SimulatorShopPad.rbxl (58.5 KB)
Hope this helps and happy developing!
That post is only 3 years old, and can/could still be relevant for finding useful information about this topic.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.