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

Moving Object, Filtering Enabled help?

Asked by 6 years ago

So I'm trying to make a boat seat move and I'm not 100% clear on Filtering Enabled yet but if you can help and explain this to me a bit, I would really appreciate it.

I don't know if I did this right?

so Both the MoveEvent and StopEvent are in the VehicleSeat, as well as the localscript and script, are in the vehicleseat as well.

--Client

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local MoveEvent = script:WaitForChild("MoveEvent")
local StopEvent = script:WaitForChild("StopEvent")

local KeysDown = {}

UserInputService.InputBegan:connect(function(Input)
    local KeyCodeName = Input.KeyCode.Name

    if KeyCodeName == "W" then
        MoveEvent:FireServer("Forwards")
    elseif KeyCodeName == "S" then
        MoveEvent:FireServer("Backwards")
    elseif KeyCodeName == "A" then
        MoveEvent:FireServer("Left")
    elseif KeyCodeName == "D" then
        MoveEvent:FireServer("Right")
    end

    if KeyCodeName ~= "Unknown" then
        KeysDown[KeyCodeName] = true
    end
end)

UserInputService.InputEnded:connect(function(Input)
    local KeyCodeName = Input.KeyCode.Name  

    if KeyCodeName == "W" then
        if KeysDown["S"] then
            MoveEvent:FireServer("Backwards")
        else
            StopEvent:FireServer("Forwards")
        end
    elseif KeyCodeName == "S" then
        if KeysDown["W"] then
            MoveEvent:FireServer("Forwards")
        else
            StopEvent:FireServer("Backwards")
        end
    elseif KeyCodeName == "A" then
        if KeysDown["D"] then
            MoveEvent:FireServer("Right")
        else
            StopEvent:FireServer("Left")
        end
    elseif KeyCodeName == "D" then
        if KeysDown["A"] then
            MoveEvent:FireServer("Left")
        else
            StopEvent:FireServer("Right")
        end
    end

    if KeyCodeName ~= "Unknown" then
        KeysDown[KeyCodeName] = nil
    end
end)
--Server

local Boat = script.Parent
local Players = game:GetService("Players")

local MoveEvent = script:WaitForChild("MoveEvent")
local StopEvent = script:WaitForChild("StopEvent")

Boat.MaxSpeed = 18
maxspeed = Boat.MaxSpeed
Boat.BodyPosition.position = Boat.Position
Boat.BodyGyro.cframe = Boat.CFrame
speed = 0

Boat.ChildAdded:connect(function(Weld)
    if Weld:IsA("Weld") then
        local Torso = Weld.Part1    
        if Torso then
        end
    end
end)

Boat.ChildRemoved:connect(function(Child)
end)

MoveEvent.OnServerEvent:connect(function(Player, Type)
    if Type == "Forwards" then
        Forwards = 1
        if speed < maxspeed then speed = speed + 0.1 end
        Boat.BodyVelocity.velocity = Boat.CFrame.lookVector*speed
    elseif Type == "Backwards" then
        Forwards = -1
        if speed < 18 then speed = speed + 0.1 end
        Boat.BodyVelocity.velocity = Boat.CFrame.lookVector*-speed
    elseif Type == "Left" then
        Turn = -1
        Boat.BodyGyro.cframe = Boat.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,0.01,0)
    elseif Type == "Right" then
        Turn = 1
        Boat.BodyGyro.cframe = Boat.BodyGyro.cframe * CFrame.fromEulerAnglesXYZ(0,-0.01,0)
    end
end)

StopEvent.OnServerEvent:connect(function(Player, Type)
    if Type == "Forwards" or Type == "Backwards" then
        Forwards = nil
    elseif Type == "Left" or Type == "Right" then
        Turn = nil
    end
end)

Answer this question