it should jsut be printing “Vortexuel560” but it also prints a bunch of data about my account…
Heres the script:
local Event = game.ReplicatedStorage:WaitForChild("MoveRequest")
local seat = script.Parent.Seat
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local Stp1 = seat.Occupant.Parent.Name
local Stp2 = game.Players:FindFirstChild(Stp1)
print(Stp2)
end)
The issue is that seat.Occupant.Parent.Name gives you the name of the model in which the player’s character is, not the player object itself. To get the Player object, you should use seat.Occupant , which already returns the Player object if the seat is occupied by a player.
This script will print the name of the player whenever the occupant of the seat changes. If the seat is unoccupied, it won’t print anything.
local Event = game.ReplicatedStorage:WaitForChild("MoveRequest")
local seat = script.Parent.Seat
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local occupant = seat.Occupant
if occupant then
print(occupant.Name)
end
end)
UserInputService and ContextActionService. Here’s how you can modify your script to achieve this, also it has to be Local Script:
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local seat = (Seat Location)
-- Function to handle player input
local function onAction(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
print("Player is pressing:", inputObject.KeyCode)
end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local occupant = seat.Occupant
if occupant then
-- Connect the input function only when the occupant enters the seat
ContextActionService:BindAction("SeatInput", onAction, false, Enum.KeyCode.Space) -- Change Enum.KeyCode.Space to the key you want to listen to
else
-- Unbind the input function when the occupant leaves the seat
ContextActionService:UnbindAction("SeatInput")
end
end)
This is example with the mentioned services as @Bovious learn more in the documentation
Yeah, the guy above me nailed it. I recommend you take a look at remoteEvents, remoteFunctions, bindableEvents, bindableFunctions and the client server boundary.
Assuming the seat is directly under the Workspace and its name is “Seat”, the script should look like this:
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
-- Assuming the seat is directly under the Workspace
local seat = game.Workspace:WaitForChild("Seat")
-- Function to handle player input
local function onAction(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
print("Player is pressing:", inputObject.KeyCode)
end
end
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local occupant = seat.Occupant
if occupant then
-- Connect the input function only when the occupant enters the seat
ContextActionService:BindAction("SeatInput", onAction, false, Enum.KeyCode.Space) -- Change Enum.KeyCode.Space to the key you want to listen to
else
-- Unbind the input function when the occupant leaves the seat
ContextActionService:UnbindAction("SeatInput")
end
end)
It would be better if you send an image of your game’s explorer included your seat in workspace