Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Mouse button/ Keyboard key Problem?

I have this script in a vehicleSeat and i want it to find my player when i sit and be able to use Q, E and the mouse button.

right now i get the error : MouseButton1Down is not a valid member of PlayerMouse at line 30 but i think there are other things not working.

local sit = false
function onTouched(hit) 
    if hit.Parent.Humanoid ~= nil then
            if sit == false then
	           sit = true
       local plr = hit.Parent.Name
       local player = game.Players:FindFirstChild(plr)
       local mouse = player:GetMouse()
       local s = script.Parent.TurnSpeed/140

-- Q and E
 
    mouse.KeyDown:connect(function(key)
	--key = key:lower()
        if key == "q" then
                   script.Parent.BodyGyro.cframe = script.Parent.CFrame*CFrame.fromEulerAnglesXYZ(0, s, 0)
        end
        if key == "e" then
                   script.Parent.BodyGyro.cframe = script.Parent.CFrame*CFrame.fromEulerAnglesXYZ(0, -s, 0)
        end            
    end)

-- Mouse

    mouse.MouseButton1Down:connect(function(key)   
                   print 'firing'
    end)
sit = false
    end
end
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

Here you go :D You simply made the mistake of having "Mouse" for the "Button1Down"

function onTouched(hit) 
    if hit.Parent.Humanoid ~= nil then
       local plr = hit.Parent.Name
       local player = game.Players:FindFirstChild(plr)
       local mouse = player:GetMouse()
       local s = script.Parent.TurnSpeed/140
       local clickQ = false
       local clickE = false
       local clickM = false

-- Q and E

    mouse.KeyDown:connect(function(key)
    --key = key:lower()
        if key == "q" then
            if clickQ == false then
               clickQ = true
                   script.Parent.BodyGyro.cframe = script.Parent.CFrame*CFrame.fromEulerAnglesXYZ(0, s, 0)
               clickQ = false
            else
               clickQ = false
            end
        end
        if key == "e" then
            if clickE == false then
               clickE = true
                   script.Parent.BodyGyro.cframe = script.Parent.CFrame*CFrame.fromEulerAnglesXYZ(0, -s, 0)
               clickE = false
            else
               clickE = false
            end
        end            
    end)

-- Mouse

    mouse.Button1Down:connect(function(key) -- it's Button1Down not "MouseButton1Down"
            if clickM == false then
               clickM = true
                   print ("firing")
               clickM = false
           else
               clickM = false
           end      
    end)
	else print("Humanoid only!") -- incase it doesn't have a Humanoid :D
    end
end

script.Parent.Touched:connect(onTouched)

1 comment

0

Thank you but the parts where i want to press Q and E dont work and i dont get any errors can you help me on this?

This discussion is preserved as it was. New answers, comments, and votes are closed.