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

How do I unlock the mouse in a GUI?

Asked by 3 years ago

I am having a problem that when I click on the shopkeeper, the GUI pops up but the mouse is stuck in first person. I know I'm supposed to use "modal = true" but I can't figure out what to put before the ".modal" The roblox wiki said use GuiButton.modal = true but it gives me an error when I type that.

game.Workspace["Gun Shop Owner"].ClickDetector.MouseClick:Connect(function()
    script.Parent.Frame.Visible = true
    GuiButton.Modal = true
end)

here's the very short script. I'm trying to set the value to true when the Gui is pulled up and then I'll set it to false once it is closed. I can't do much until I figure this out even though it doesn't seem like it should be that hard. I'm just a bit confused about it. Can anyone fix this? thanks!

0
try to replace "GuiButton" with "script.Parent.Frame" the8bitdude11 358 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
local GuiButton = script.Parent:WaitForChild("yourbuttonname")
local frame = script.Parent:WaitForChild("Frame")
workspace["Gun Shop Owner"].ClickDetector.MouseClick:Connect(function()
    frame.Visible = true
    GuiButton.Modal = true -- guibutton is not defined here, define guibutton out of the mouseclick function (i did it above for you, rename the string)
end)

--[[ notes

GuiButton is a reference for both ImageButton and TextButton (saying button:IsA("GuiButton") will return true)

use "workspace" as it is faster and is a global variable

index your ui elements so you do not have to write script.parent.parent etc every time you need to edit or add something
]]

https://developer.roblox.com/en-us/api-reference/class/GuiButton

0
I had to change it up a bit as the "Button" to get this gui is an npc. I had to put the local script inside of the Frame and call Parent.Parent for the Frame. DaGlizzzzzzyyyy 34 — 3y
0
~~~ local GuiButton = script.Parent:WaitForChild("Button") local frame = script.Parent.Parent:WaitForChild("Frame") workspace["Gun Shop Owner"].ClickDetector.MouseClick:Connect(function() frame.Visible = true GuiButton.Modal = true end) ~~~ DaGlizzzzzzyyyy 34 — 3y
Ad

Answer this question