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
elseif Magic.Value == false then
Magic.Value = true
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
elseif Magic == false then
Magic = true
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
elseif Magic.Value == false then
Magic.Value = true
end
end
end)
The script will now wait until your player renders. Then it will wait until the bool value is rendered.
6 comments
Not sure, but maybe try using the binding function from the ContextActionService tutorial? http://wiki.roblox.com/index.php?title=ContextActionService_tutorial
Seems slightly too advanced for my level.
I would first add a 'print' before the KeyDown function to make sure that "MagicEquipped" is found in the player.
Sorry, i'm a printing noob, how would I go about that?
game.Players.LocalPlayer:GetMouse() is correct, don't worry.
Damn, something is wrong, because it doesn't work, just can't find what.