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

How come my code for left click detect works in Studio, but not in Server/Client?? Mouse is nil?

Asked by 8 years ago

The code works without the left click detect, but I need the script to not run if right clicked.

local clickDetector = script.Parent
local buttonPressed = false
local ClickModule = require (game:GetService("ServerScriptService").ModuleScript)

function OnClick(Clicker)
    if not buttonPressed then   
        buttonPressed = true
            ClickModule(Clicker, script.Parent.Parent)
        wait()
        buttonPressed = false
    end
end

clickDetector.MouseClick:connect(OnClick)

Unfortunately it doesnt with it. I didnt realize this until I used the Server test and it returned Mouse is nil???

local clickDetector = script.Parent
local buttonPressed = false
local ClickModule = require (game:GetService("ServerScriptService").ModuleScript)

local OnClick
OnClick = clickDetector.MouseClick:connect(function(Clicker)
    if not buttonPressed then   
        buttonPressed = true
        local Mouse = Clicker:GetMouse()
        local event
        event = Mouse.Button1Down:connect(function()
            ClickModule(Clicker, script.Parent.Parent)
        end)
        wait()
        buttonPressed = false
        event:disconnect()
    end
end)
0
It may be because the script needs to be a LocalScript to be able to index 'Clicker'. This means you will also have to move the ClickModule to ReplicatedStorage, because the client cannot access any 'Server...' services. TheDeadlyPanther 2460 — 8y
0
I turned it into a LocalScript and moved clickmodule to replicatedstorage, but now the onClick funtion isnt even being run, i know because i put a print in there at the beginning and it isnt showing when clicked on. xSantaBear 5 — 8y

Answer this question