Forum > Scripts >

[REQ] Just remind me

Posts: 212

Threads: 42

Joined: May, 2018

Reputation: 0

Posted

I am working on how to toggle a script with a button. Tell me what I did wrong on this script.


local player = game.Players.LocalPlayer
local Mouse = game.Players.LocalPlayer:GetMouse(function(key)

key == "e" then
print("You pressed e")
end
end
end)
  • 0

Posts: 41

Threads: 17

Joined: Apr, 2018

Reputation: 0

Replied

I'm aware this is a little late, but anyways

Couple of things wrong:
1. You did not establish a proper mouse variable (it's just player:GetMouse());

2. When you attempted to establish the upvalue "Mouse", you instead did an improper way of connecting to it - you called GetMouse(), but you gave a function, when the GetMouse() function does not need arguments, so in this case... the function would be ignored

3. You did not give an proper "If" statement, that's where an error would be generated.

4. You gave an arbitrary "End" statement (aka you put an end where it is not needed, thus raising an error)

+: You said you wanted to toggle a script with a button, I don't see a button variable / path anywhere.

The proper way to do this script would be:

local player = game:GetService('Players').LocalPlayer;
local mouse = player:GetMouse();

mouse.KeyDown:connect(function(key)
 Â Ã‚ Ã‚ Ã‚  if (key == 'e') then
 Â Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚ Ã‚  print('You pressed "e".');
 Â Ã‚ Ã‚ Ã‚  end
end);

It would be a newcomer's mistake to do this, so I don't blame you.
  • 0

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )