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

Mouse button/ Keyboard key Problem?

Asked by
Paldi 109
9 years ago

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

Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
9 years ago

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)

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? Paldi 109 — 9y
Ad

Answer this question