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

Is it possible to call a Mouse Button event in SSS?

Asked by
Xonois -3
5 years ago

So, I want to call a MouseButton1Click event from a gui from a script in the Server Script Service but the script I've tried doesn't work. Is there a way that you can call MouseButton1Down from a script in SSS? Here's my script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EV = ReplicatedStorage:WaitForChild("Events")
local StarterGui = game:GetService("StarterGui")
local Persona = StarterGui.ChoosePersonality.PersonaFrame
local Channel = StarterGui.ChooseChannel.ChannelFrame
local CM = EV:WaitForChild("ChoseMny")
local CS = EV:WaitForChild("ChoseSmart")
local TK = EV:WaitForChild("ChoseTlk")
local OT = EV:WaitForChild("ChoseOutgng")


function mnyClick()
Persona:Destroy()
Channel.Visible = true
end
Persona.mnyhngry.MouseButton1Click:connect(mnyClick)

2 answers

Log in to vote
1
Answered by 5 years ago

MouseButton1Click cannot be listened for from the server. Heck the server shouldn't have any business in GUIs anyways. Simply use a LocalScript. Also, the GUIs themselves are inside the PlayerGui, not the StarterGui. StarterGui is basically what the PlayerGui clones out of, so the GUIs, any running LocalScripts in there are in PlayerGui.

-- localscript under mnyhungry
local player = game:GetService("Players").LocalPlayer -- player
local playerGui = player:WaitForChild("PlayerGui")

script.Parent.Activated:Connect(function()
    playerGui.ChoosePersonality.PersonaFrame:Destroy()
    playerGui.ChooseChannel.ChannelFrame.Visible = true
end)

It is also worth noting your function was poorly indented. Even if it's only two lines, your code should always be indented properly. Also, :connect() with a lowercase c is deprecated, use :Connect() with an uppercase C.

Ad
Log in to vote
0
Answered by 5 years ago

Server Script Service is server side and cannot modify player's gui. Gui interactions like MouseButton1Click must be called from a LocalScript.

Answer this question