Hello, I would like to know how can I use my localscript in my model (a script that move the model from keys input with UIS). I mean, I would like to have the script enable for the player that is on the main Seat and can move the car only if the player is on it :
You can’t move a model with a script by changing pivots so the only way you can do it is by having a origin part in the middle of the car and have every part welded to it and then you just move that part and everything else will move with it.
local UserInputService = game:GetService("UserInputService")
local Car = script.Parent.Parent
local seat = Car:FindFirstChild("MainSeat")
local rotationSpeed = 1
local Moving = false
UserInputService.InputBegan:Connect(function(input, _gameProceesedEvent)
if input.KeyCode == Enum.KeyCode.W and not _gameProceesedEvent and seat.Occupant then
if Moving then return end
Moving = true
while Moving == true do
Car:PivotTo(Car:GetPivot() * CFrame.new(0,0,1))
task.wait(0.01)
end
elseif input.KeyCode == Enum.KeyCode.S and not _gameProceesedEvent and seat.Occupant then
if Moving then return end
Moving = true
while Moving == true do
Car:PivotTo(Car:GetPivot() * CFrame.new(0,0,-1))
task.wait(0.01)
end
elseif input.KeyCode == Enum.KeyCode.D and not _gameProceesedEvent and seat.Occupant then
if Moving then return end
Moving = true
while Moving == true do
Car:PivotTo(Car:GetPivot() * CFrame.Angles(0,-math.rad(rotationSpeed),0))
task.wait(0.01)
end
elseif input.KeyCode == Enum.KeyCode.A and not _gameProceesedEvent and seat.Occupant then
if Moving then return end
Moving = true
while Moving == true do
Car:PivotTo(Car:GetPivot() * CFrame.Angles(0,math.rad(rotationSpeed),0))
task.wait(0.01)
end
end
end)
UserInputService.InputEnded:Connect(function(input, _gameProceesedEvent)
if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.S then
if not Moving then return end
Moving = false
end
end)
One I gave before that get inputs from user like a Localscript.
The last is a way to don’t use remote events to ask for every frames :
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
char.Humanoid.Seated:Connect(function(active, seat)
if seat == nil then return end
if seat.Parent == script.Parent.Parent then
seat:SetNetworkOwner(plr)
print(active, plr.Name)
end
end)
end)
end)