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

Key pressed problem?

I have a problem with my script i made for a flying vehicle, i want that when the player get on the seat, he can use Q and E to have more movement controls but it dont work and i dont get any errors..

ps: the "--mouse" section is working.

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)
        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)   
	        if clickM == false then
	           clickM = true
                   print 'firing'
               clickM = false
           else
	           clickM = false
	       end      
    end)

    end
end

script.Parent.Touched:connect(onTouched)

1 answer

✓ Accepted answer

The mouse is only accessible from a localscript, localscripts only work if they are stored in something directed towards the client.

You need to look into RemoteEvents / RemoteFunctions

Sorry i can't give you a more straightforward answer, but doing so would mean me remaking your whole code.

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