I have a script that gives a player 20 points every 20 seconds in the leaderboard at all times. I use an A-Chassis and I am wondering on how to make it so that the player earns points when they are seated in Vehicle Seat.
Try making a script that fires when the player sits in the vehicle, then awards the points. Reading this might help.
A seat has a property of “Occupant”, which is returning a humanoid that sits in it.
A humanoid also has a “Seat part” property in it, so you could just do it this way:
function AwardMoney(player) if player.Character.Humanoid.SeatPart:IsA("DriverSeat") then -- Give money. end end
Completely useless, you should definitely read this article.
I think you can make it so when it goes through the players to award them points, check if their Humanoid’s
SeatPart property is not nil, and if it isn’t
nil, award them the points
Pseudo Code example
for _,player in pairs(Players:GetPlayers()) do local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") if not humanoid or not humanoid.SeatPart or humanoid.SeatPart.ClassName ~= "VehicleSeat" then continue end --Award points here end
If they don’t have a humanoid eitheer because character doesn’t exist of it wasn’t found OR their
SeatPart property is nil, it goes to the next player, otherwise, it awards the points. Although I think you’d need to filter for VehicleSeats after checking if the SeatPart properly is not empty
I see, because my despawn system is in driver seat and it has the property “occupant”. Thank you for answering my question.
No problem! I could recommend you visiting ROBLOX DevHub for API references when you’re stuck with similar issues. It has a lot of useful documentation in it for any solution to be found.
It would still allow awarding points even if a person sits on a simple chair.
so do vehicle seat and seat have different properties or are they the same? Vehicle seat has a speed gui and seat is just a chair.
Hence why I editted my post to mention it may require a change in the if statement to filter for Vehicle seats, such as
if not humanoid or not humanoid.SeatPart or humanoid.SeatPart.ClassName ~= "VehicleSeat" then
The difference is the “ClassName” and a functional.
Seat is here in order to executive a “Sit” animation on the player and “attach it” to a certain “part”.
VehicleSeat allows you to control different mechanisms via. a script, as it receives player’s input filtered accordingly to the properties of the vehicle seat.
So can I have the vehicle seat and server script service script running at the same time with no issue? Since I have a point giving system running at all time, but also the player will get even more points when they are in vehicle seat.
I can not see any issues with it, heh. Usually vehicle seats are controlled by a script which would be oriented on “controlling actions vehicle seat requests”.
It would require small changes inside your code, example script:
function AwardMoney(player) if player.Character.Humanoid.SeatPart:IsA("DriverSeat") then -- Give more money. else -- Give less money. end end
would this be correct? function AwardCarSimPoints (player)
if player.Character.Humanoid.SeatPart:IsA(“DriverSeat”) then
local giveTime = 3
local stats = plr:FindFirstChild(‘leaderstats’)
if stats then
stats.CarSimPoints.Value = stats.CarSimPoints.Value = 200
Oh so that means I have to put the script in server script service and not in vehicle seat?
Why do you try to place two
= signs? Perhaps you wanted to put
I don’t really get where you were going to use the “GiveTime” variable.
But yeah, something like this:
local giveTime = 3 local Enabled = true function AwardCarSimPoints (player) local stats = plr:FindFirstChild(‘leaderstats’) if stats then if player.Character.Humanoid.SeatPart ~= nil and player.Character.Humanoid.SeatPart:IsA("VehicleSeat") then stats.CarSimPoints.Value = stats.CarSimPoints.Value + 200 else stats.CarSimPoints.Value = stats.CarSimPoints.Value + 150 end end end repeat wait(GiveTime) for _, player in pairs(game.Players:GetPlayers()) do AwardCarSimPoints(player) end until Enabled == false
Yeah, you can easily manage funding from a single script located in the server script service.
Thank you for your support, I really appreciate it. Good day to you.
No problem, feel free to message me anytime if you need help. Good luck with your project!
So once the script is in server script service, do I still keep my giving points system?
The code I provided must be implemented into your giver system, I did not write anything to set up leaderstats assuming that you would place my code into your original script.