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

My script is throwing an error and I don't know why?

Asked by 4 years ago

I'm trying to make the body velocity increase when your in a seat, but it can't find the seat.

Local Script inside StarterPlayerScripts

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() 
local SpeedValue = player.ValueFolder.SpeedValue

game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(KeyPressed)
    if KeyPressed == "w" then
        if character.Humanoid.Sit == true then
            local SeatName = character.Humanoid.SeatPart.Name
            print(SeatName)
            SpeedValue.Value = SpeedValue.Value + 1
            print(SpeedValue.Value)
            game.ReplicatedStorage.W:FireServer(character, SpeedValue, SeatName)
        end
    end

    if KeyPressed == "s" then
        if character.Humanoid.Sit == true then
            local SeatName = character.Humanoid.SeatPart.Name
            print(SeatName)
            SpeedValue.Value = SpeedValue.Value - 1
            print(SpeedValue.Value)
            game.ReplicatedStorage.W:FireServer(character, SpeedValue, SeatName)
        end
    end
end)

Server Script in ServerScriptStorage

game.ReplicatedStorage.W.OnServerEvent:Connect(function(character, SpeedValue, SeatName)
    local seat = game.Workspace:FindFirstChild(SeatName)
    local look = seat.Parent.Floor.CFrame.LookVector
    seat.Parent.Floor.BodyVelocity.Velocity = look * SpeedValue.Value
end)

game.ReplicatedStorage.S.OnServerEvent:Connect(function(character, SpeedValue, SeatName)
    print("S")
end)

The error line:

  Class37Seat -- Print
  6 -- Print
  19:46:44.603 - Argument 1 missing or nil -- Error
 19:46:44.604 - Stack Begin
 19:46:44.604 - Script 'ServerScriptService.Script', Line 2
 19:46:44.604 - Stack End

Thank you for any help!

1 answer

Log in to vote
0
Answered by
waifuSZN 123
4 years ago

SeatName needs to be in quotes.

Ad

Answer this question