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

What's wrong with this script?

Asked by 4 years ago
Edited 4 years ago
local menu = game.Players.LocalPlayer.PlayerGui.Gui.Menu
local userInputService = game:GetService("UserInputService")
local menuOut = false
local cooldown = false

userInputService.InputBegan:Connect(function(input, isTyping)
    if isTyping then return
        else if cooldown == false and menuOut == false and input.KeyCode == Enum.KeyCode.M then
            game.ReplicatedStorage.RemoteEvent.MenuOut:FireClient()
            menuOut = true
            cooldown = true
            wait(1)
            cooldown = false
        else if cooldown == false and menuOut == true and input.KeyCode == Enum.KeyCode.M then
                game.ReplicatedStorage.RemoteEvent.MenuIn:FireClient()
                menuOut = false
                cooldown = true
                wait(1)
                cooldown = false
            end
        end     
    end
end)

The above script was meant to fire a remote event to a local script

local menu = script.Parent

game.ReplicatedStorage.RemoteEvent.MenuIn.OnClientEvent:Connect(function()
    menu:TweenPosition(UDim2.new(1,0, -0.05,0),"Out","Quad",0.5,false)
end)

game.ReplicatedStorage.RemoteEvent.MenuOut.OnClientEvent:Connect(function()
    menu:TweenPosition(UDim2.new(0.8,0, -0.05,0),"Out","Quad",0.5,false)
end)

When M was pressed, then the "menu" would move in/out

But it doesn't seems to work, can anyone help?

1 answer

Log in to vote
1
Answered by 4 years ago

A GUI menu cannot be modified by a server script.

Since GUIs only exist on a player's screen, the server cannot have access to it. The only code that should make the menu tween will need to be handled on the client-side (in the LocalScript), removing the need for a RemoteEvent here.

If you're trying to tween the GUI for everyone you'll have to send a message to the server (FireServer) from the input script, then the server will need to tell each client to tween the GUI (FireAllClients)

This goes into more detail on the Server-Client interactions https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Ad

Answer this question