Well there are a ton of methods to get a player, but I will give you the simplest ones which I believe you are talking about.
--- Touch
script.Parent.Touched:Connect(function(Touched)
if game.Players:FindFirstChild(Touched.Name) then
end
end)
--- Join
game.Players.PlayerAdded:Connect(function(Player)
end)
if I understood u correctly. You are basically checking if player touched the bus sensor. Your approach seems okay to me, a basic example would be
Sensor.Touched:Connect(function(hit)
local Hum = hit.Parent:FindFirstChild("Humanoid")
local plr = Hum and game.Players:GetPlayerFromCharacter(Hum.Parent)
if plr then
--plr is now a confirmed Player
end)
are u talking about hit.Parent or just hit? if only hit then its not possible that its a model because the documentation states that Touched event can only return basepart
I try to follow you, but seems that not enough info is provided or “confusing”
Could you explain exactly, the behavior that your “bus”, “sensor”, “player interactions”, “scenario where this could happen”, “detailed mechanics” you are building.
Otherwise I find hard to understand what you mean.
If you really want to use .Touched you could make a table containing all the parts you want to ignore.
Example:
local IgnoreTable = {} -- Bus Model, or what the bus parts are parented to, you could also add individual parts
local Players = game:GetService("Players")
Sensor.Touched:Connect(function(Hit)
if not table.find(IgnoreTable, Hit.Parent) and not table.find(IgnoreTable, Hit) then -- Checking if the parent of the hit is in the ignore table and if the hit part itself is in the ignore table
if Hit.Parent:FindFirstChildOfClass("Humanoid") ~= nil then
local Player = Players:GetPlayerFromCharacter(Hit.Parent)
-- Now you have the player and can continue your code
end
else
return
end
part.Touched:Connect(function(hit)
if hit.Parent and hit.Parent:FindFirstChildOfClass("Humanoid") then
local character = hit.Parent
local player = game.Players:GetPlayerFromCharacter(hit.Parent
end
end)
I still don’t really see why you’re so hesitant on using PlayerAdded, It won’t lag your game at all even if its multiplayer.
Actually right i have solved the problem,i use a bindable event to get the player and i think i am not going to use hit.Parent because the hit.Parent will be different everytime as there are lots of parts combined.
I already know it is not gonna work because if i do that,when there is a second player added in,the newplayer varaible will changed because it is a new one and also this is a server script (Local script would be easier to get the player)(server script will be harder to get the player)(Also,server scrips are better for passengers script.