Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Key pressed problem?

Asked by
Paldi 109
5 years ago

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

Log in to vote
1
Answered by
Goulstem 8139 Badge of Merit Moderation Voter Administrator Community Moderator
5 years ago

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.

Ad

Answer this question