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

why does my mouse click input method not work in-game, but works fine in studio test mode?

Asked by
movsb 242 Moderation Voter
7 years ago

For example, if I made a local script saying:

local plr = game.Players.LocalPlayer;
local m = plr:GetMouse();
m.Button1Down:connect(function()
    print(plr.Name.."'s mouse clicked");
end)

it would work perfectly in-studio test mode, but when you go to play the actual game on your ROBLOX client (In-game) it doesn't work at all! Now your next instinct may be to use UserInputService, but if I altered the local script to:

local plr = game.Players.LocalPlayer;
game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("plr.Name.."'s mouse clicked");
    end
end)

But this still behaves the same way! It STILL will only work in-studio mode, and it literally won't work at all in-game. Did ROBLOX deprecate these methods? should I be using a remote function instead? I am kind of lost with this, I need to get this mouse click input to work in-game. Any help would be much appreciated, thanks.

2 answers

Log in to vote
1
Answered by 7 years ago

Well, srsly m8 im a harambe at scripting but this is vry new to players

sometisem the local game runs faster then a server so in a local session the game runs on par with the server sense it's hosted locally k :)

so to compensate for the delay from local to server which is your problem here is that your local scripts is to sanic fast then the server you gotta add a delay man

local plr = game.Players.LocalPlayer;
repeat wait() until plr; 
game:GetService("UserInputService").InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("plr.Name.."'s mouse clicked");
    end
end)

0
What a terrible answer. User#11440 120 — 7y
0
are you trolling or something devan? The game I am making the script in is filteringEnabled, I use a remoteEvent to check and fire when a player first joins, there would be no need for a repeat wait() until plr in my main local script. movsb 242 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

You're probably placing the Local Script in the wrong place.

Local Scripts can not run in Workspace or ServerScriptService. You should be using ReplicatedFirst, StarterPack, StarterGui, StarterPlayerScripts, or some other service that gets replicated to the player and allows Local Scripts to run.

That's all I see that could possibly be wrong.

Good Luck!

If I helped, please don't forget to accept my answer. This will help you and be a lot. Thank you.
0
nope, I always place any client based scripts including this one in the starterPlayerScripts Service. movsb 242 — 7y
0
Works fine for me. User#11440 120 — 7y

Answer this question