local part = script.Parent
local plr = game.Players.LocalPlayer
local driverseat = script.Parent.Parent.Parent:FindFirstChild("DriveSeat")
local function findPlayerCharacter()
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
return player.Character
end
end
end
local function findPlayerHumanoid()
local playerCharacter = findPlayerCharacter()
if playerCharacter then
return playerCharacter:FindFirstChildOfClass("Humanoid")
end
end
local function carhit(otherPart)
-- Check if the player's humanoid is in the workspace and the player is seated in the driver seat
local humanoid = findPlayerHumanoid()
if humanoid and driverseat.Occupant == humanoid.Parent and otherPart == driverseat then
-- Make it so when the player hits a wall at a velocity enough to damage the player inside the driver seat, damage is based on the speed of the car
local speed = driverseat.Velocity.Magnitude
if speed > 50 then
humanoid:TakeDamage(speed / 10)
end
end
end
part.Touched:Connect(carhit)
What I’m trying to accomplish is: get the character of the player in the driverseat and damage their humanoid if they hit a wall at enough speed to damage them like in the script. nothing appears in the output
What you probably need to do is Weld an invisible brick in front of the car, and connect a Touched function to it. Once the Touched function makes contact with a wall, check if the car speed is over the threshold then make the player take damage.
" This event only fires as a result of physics movement, so it will not fire if the CFrame property was changed such that the part overlaps another part. This also means that at least one of the parts involved must not be BasePart.Anchored at the time of the collision."
You can’t use .Touched on anchored objects. You need to either unanchor the parts in the car, or find another way to check collisions using for example raycasting (this is probably too difficult for you, judging by what you’re stuck on)
Yeah, it’s difficult, I’m just trying to make it damage the player when the player hits a wall with the car, not damaging another player if they hit another player, but damaging the driver’s humanoid.
local part = script.Parent
local driverseat = script.Parent.Parent.Parent:FindFirstChild("DriveSeat")
local function getOccupantHumanoid()
local occupant = driverseat.Occupant
if occupant then
local character = occupant.Parent
if character then
return character:FindFirstChildOfClass("Humanoid")
end
end
end
local function carhit(otherPart)
local humanoid = getOccupantHumanoid()
if humanoid then
local speed = driverseat.Velocity.Magnitude
if speed > 50 then
humanoid:TakeDamage(speed / 10)
end
end
end
part.Touched:Connect(carhit)