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

Any way to detect GuiButton.MouseButton1Down from ServerScript?

Asked by 4 years ago
Edited 4 years ago

I am trying to make a ServerScript that needs to detect gui button presses. My script does not highlight as an invalid operation, but it simply doesnt work. I don't want to have to use a localscript, as i would like to make this a requireable modulescript.

CloseButton = game.Players.pname.PlayerGui.Gui.Frame.Button
CloseButton.MouseButton1Down:connect(function()
    digga.Enabled = false
end)

Edit: Just to fully clarify this, i do not want to use a RemoteFunction or RemoteEvent as a method, plainly because i want to be able to make a ModuleScript with this in, upload it to Roblox and Require() it in a ServerScript. If you do not know how to solve this without the direct use of a pre-existing LocalScript then your method is not what i'm looking for.

0
why do you need to do it on the server? royaltoe 5144 — 4y
0
because it's going to be in a model that i can require in a script, and that script is gonna be a server script User#29786 0 — 4y
0
just to clarify - you want to click a button and a model spawns then another script on the server is going to reference that model in a variable? royaltoe 5144 — 4y
0
use a remoteevent EmbeddedHorror 299 — 4y
View all comments (2 more)
0
I don't want to have to use a localscript, as i would like to make this a requireable modulescript. User#29786 0 — 4y
0
-1. You NEED a local script as user input/user interface should not be known by or handled by the server. Stick with your only option. Use remotes. programmerHere 371 — 4y

2 answers

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

AFTER EDIT: (With ModuleScript)

let's say this is your module script (remember to put it somewhere the localplayer can access like replicatedstorage or workspace)

local module = {}
module.Model = game.Workspace.Model

function module.CloneModel()
    local modelClone = module.Model:Clone()
    modelClone.Parent = game.Workspace
end
return module

require module from localscript and call it's clone model function

module = require(game.Workspace.ModuleScript)
module.CloneModel()

alternatively, you could get the model from the module script and clone the model in the local script:

module = require(game.Workspace.ModuleScript)
model = module.Model
local modelClone = model:Clone()
modelClone.Parent = game.Workspace


BEFORE EDIT: (With Remote Events)

Create a remote event object in the replicated storage and name it "spawnModel"

fire the remote event to send to the server when the player clicks a button

closeButton = script.Parent.Frame.Button

closeButton.MouseButton1Down:connect(function()
    game.ReplicatedStorage.spawnModel:FireServer("modelNameGoesHere")
end)

Have a function be called when that remote event gets fired spawning the model:

--function that spawns our model
local function spawnModel(player, modelToSpawn)
    local model = game.ReplicatedStorage:FindFirstChild(modelToSpawn)

    --clone the model into the workspace if the model exists 
    if(model)then
        local modelClone = model:Clone()
        modelClone.Parent = game.Workspace
    end
end

--connect the remote event to the function
game.ReplicatedStorage.spawnModel.OnServerEvent:Connect(spawnModel)

0
I want to have my script all run from one require() function, but creating then editing the source of a LocalScript from the sever won't work for obvious reasons. User#29786 0 — 4y
0
alright, i made an edit that should work now royaltoe 5144 — 4y
0
if thats not what you are asking for let me know royaltoe 5144 — 4y
0
pls reply bc this took me a long time to write royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

User input such as this cannot be detected from the server, it has to be picked up by a local script, you can definitely use a ModuleScript and require it localside, and then pass it onto the server any way you want, but there is no definite way for the server to pick up client input.

Answer this question