I have a series of code that detects a vehicle, this code is irrelevant. What does matter is that once I have found the vehicle I need to find the driver of said vehicle and then the players leader stats. I have no idea of how to do this so any help or ideas are much appreciated.
The extra bits. Firstly the script is in a button which is defined in the script below as theobject. It works and prints yay but after then (bit finding vehicle owner) does not work. There are also various scripts in the Vehicle seat if that effects the code here with function(child) bit.
Heres the code:
local v1 = game.Workspace.Vehicle1
local theobject = script.Parent
theobject.Touched:connect(function(p)
if p.Parent == v1 then
print ("Yay")
v1.VehicleSeat.ChildAdded:connect(function(child)
if not child:IsA("Weld") then return end
if not child.Parent or not child.Part1 or not child.Part1.Parent then return end
local character = child.Part1.Parent
local player = game.Players:playerFromCharacter(character)
if not player then return end
print (":D")
print (player)
end)
ting = 0 --remove debounce
end
end)

2 comments
Are you using the same code that I posted here? https://scriptinghelpers.org/questions/1183/vehicle-camera-focuses-on-part if so, I'll edit my post there to do what you want
If it is possible to assign the vehicle to a player then yes, please.