This is all that is in the local script in the StarterGUI
wait (1) local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Magic = player:WaitForChild('MagicEquiped') local playername = player.Name mouse.KeyDown:connect(function(key) -- This bit here doesn't work if string.lower(key) == "q" then if Magic == true then Magic = false elseif Magic == false then Magic = true end end end)
EDIT: Would it be because i'm trying to get the mouse fromgame.Players.LocalPlayer
, instead of game.Workspace[playername]
should mouse (variable) be:
local mouse = game.Workspace[playername]:GetMouse()
Your variable magic is it a boolvalue? If it is then magic.value == false/true
If local Magic
or MagicEquiped
is a boolean value, then this should fix it:
wait (1) local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Magic = player:WaitForChild('MagicEquiped') local playername = player.Name mouse.KeyDown:connect(function (key) if string.lower(key) == "q" then if Magic.Value == true then Magic.Value = false -- Statement(s) elseif Magic.Value == false then Magic.Value = true -- Statement(s) end end end)
The function was meant to find the Value of the "Magic" boolean, but instead your script was coded in a way that tries to adjust its existence.
If you do want to do in the Magic = true
style (without .Value, and therefore, without needing the Boolean Value), you can make a boolean value within your script.
wait (1) local player = game.Players.LocalPlayer local mouse = player:GetMouse() local playername = player.Name local Magic = true mouse.KeyDown:connect(function (key) if string.lower(key) == "q" then if Magic == true then Magic = false -- Statement(s) elseif Magic == false then Magic = true -- Statement(s) end end end)
^^If other scripts are using MagicEquiped
, then don't use this code. xD
The Magic boolean in-script value is specifically for that script and that script only.
Just in case if the script can't find the player, then this is one of the good replacements for wait(1)
:
repeat wait() until game.Players.LocalPlayer ~= nil
EDIT
repeat wait() until game.Players.LocalPlayer ~= nil repeat wait() until game.Players.LocalPlayer.MagicEquiped ~= nil local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Magic = player.MagicEquiped local playername = player.Name mouse.KeyDown:connect(function (key) if string.lower(key) == "q" then if Magic.Value == true then Magic.Value = false -- Statement(s) elseif Magic.Value == false then Magic.Value = true -- Statement(s) end end end)
The script will now wait until your player renders. Then it will wait until the bool value is rendered.
Heyyo,
In order for you code to work "Magic" must be a BoolValue, which I assume it is... Also, you should be checking for Magic's Value property instead of Magic itself.
mouse.KeyDown:connect(function(key) if string.lower(key) == "q" then if Magic.Value == true then Magic.Value = false elseif Magic.Value == false then Magic.Value = true end end end)or, much simpler..
mouse.KeyDown:connect(function(key) if string.lower(key) == "q" then Magic.Value=not Magic.Value end; end);
Ok I think I get what your trying to do, and I don't believe you need the local mouse variable.
At the part where you said "this part doesn't work" try this;
game.Players.LocalPlayer:GetMouse() .KeyDown:connect (function(key)