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

Why can I open a menu on PC but not on Mobile?

Asked by
Dalamix 26
4 years ago

I used an Activated event to trigger this function. It works on PC but on mobile the button just goes dark when I click it, but no menu pops up. I know that the If parameter for ContinueScreen doesn't mess with it, I tried removing it and testing on mobile but same result.

Script:

button.Activated:connect(function()
    if (not main:FindFirstChild("ContinueScreen")) or (main:FindFirstChild("ContinueScreen") and main.ContinueScreen.Visible == false)   then

            menu.Position = UDim2.new(0, 0,0.2, 0)

            Sound.Pitch = 1
            Sound:Play()
            if button.Title.Text == "Menu >" then 
                button.Title.Text = "Menu <"
                button.Title.DropShadow.Text = button.Title.Text
                char.Humanoid.WalkSpeed = 0
                menu:TweenPosition(UDim2.new(0, 0,0.2, 0),"Out",'Quad',.25,true)
            elseif button.Title.Text == "Menu <" then
                Sound.Pitch = 1
                Sound:Play()
                char.Humanoid.WalkSpeed = 16
                button.Title.Text = "Menu >"
                button.Title.DropShadow.Text = button.Title.Text
                menu:TweenPosition(UDim2.new(-0.1, 0,0.2, 0),"Out","Quad",.25,true)
            end
        end 

end)

I probably made a stupid mistake but if anyone is free to help I thank you in advance.

2 answers

Log in to vote
1
Answered by 4 years ago

Here's code with my explanation, let me know if you run into any issues.

local MenuOpened = false -- I believe a variable might be good for this scenerio.

--[[
Consider using InputBegan, it's widely used and easy to figure out.

If you're wondering...

UserInputType is the type of input recieved (keyboard, mouse, touch).
UserInputState is the state of the input (begin, end, changed).
]]

button.InputBegan:Connect(function(InputObject)
    if InputObject.UserInputType == Enum.UserInputType.MouseButton1 or InputObject.UserInputType == Enum.UserInputType.Touch and InputObject.UserInputState == Enum.UserInputState.Begin then
        MenuOpened = not MenuOpened
        if not main:FindFirstChild("ContinueScreen") or (main:FindFirstChild("ContinueScreen") and main.ContinueScreen.Visible == false) then
            menu.Position = UDim2.new(0,0,0.2,0) -- Not sure why you put this here, this could interfere with the tween, I kept it anyway.
            if MenuOpened == true then
                Sound.Pitch = 1
                button.Title.Text = "Menu <"
                button.Title.DropShadow.Text = button.Title.Text
                char:FindFirstChildWhichIsA("Humanoid").WalkSpeed = 0
                pcall(menu.TweenPosition,menu,UDim2.new(0,0,0.2,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.25,true)
            else
                Sound.Pitch = 1
                char:FindFirstChildWhichIsA("Humanoid").WalkSpeed = game:GetService("StarterPlayer").CharacterWalkSpeed
                button.Title.Text = "Menu >"
                button.Title.DropShadow.Text = button.Title.Text
                pcall(menu.TweenPosition,menu,UDim2.new(-0.1,0,0.2,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.25,true)
            end
            pcall(Sound.Play,Sound)
            --[[
            'pcall' is good for preventing errors that are not necessary.
            I use it very often, and I encourage it.

            Here's a good example of it:

            local success,response = pcall(function() return "this is what response will be" end)
            print(success,reponse)
            Output:
            > true,"this is what response will be"
            ]]
        end 
    end
end)
0
I tried your script, still doesn't work. No errors at all. I think I'll just forget having support for mobile, since it doesn't work no matter what I tried. There's probably another problem that I can't find that has to do with it. Dalamix 26 — 4y
Ad
Log in to vote
0
Answered by
Dalamix 26
4 years ago

I just changed my original event which had MouseButton1Click into MouseButton1Down. For some reason it fixed everything, found it on some roblox dev forum or something. Thanks for trying to answer my question!

Answer this question