So I need to find an object in a car, but the car is named after the player, so how do I go about this? I tried this but this does not work, but it should give u an idea of what im trying to do
`
local stamina = game.Workspace.Vehicles.Player.Name… “Car”.Gui.Gas.Value
So how would I go about making it check if a player is in a seat, because this just checks and realizes its not there yet (the car is cloned when the player spawns it in) any help?
wait(1)
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local hum = player.Character:WaitForChild("Humanoid")
local fill = script.Parent
local stamina = game.Workspace.Vehicles:FindFirstChild(player.Name.."Car").Driving.Gas.Value
local canRun = true
running = false
UserInputService.InputBegan:connect(function(key, gameProcessedEvent)
if not gameProcessedEvent and canRun and key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.S or key.KeyCode == Enum.KeyCode.D then
if running then return end
running = true
while running and stamina > 0 do
fill:TweenSize(UDim2.new(stamina * 0.001, 0, 1, 0), "Out", "Quad", 0.5)
stamina = stamina - 3
wait(0.5)
end
end
end)
UserInputService.InputEnded:connect(function(key, gameProcessedEvent)
if not gameProcessedEvent and key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.A or key.KeyCode == Enum.KeyCode.S or key.KeyCode == Enum.KeyCode.D then
running = false
end
end)
while true do
if not running and stamina < 100 then
fill:TweenSize(UDim2.new(stamina * 0.01, 0, 1, 0), "Out", "Quad", 0.5)
end
if stamina >= 33 then
canSprint = true
elseif stamina == 0 then
canSprint = false
end
wait(0.5)
end
You can check if the Occupant property of the seat is the player’s humanoid
local car = workspace.Vehicles:FindFirstChild(player.Name … “Car”)
if car then
local seat = car:FindFirstChildOfClass("VehicleSeat")
if seat and seat.Occupant and seat.Occupant == player.Character.Humanoid then
-- player is in the seat
end
end
Using this will let you get the seat the player is sitting it, then you can look at it’s ancestor to reference the car or look it up by the name of the player.