Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

###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.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.