Why does this print out ALL of my account data instead of just my user?


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)

Please hep, idk what im doing

1 Like

Just mention which property you want it to print:

print(Stp2.Name)

that worked, how would i get the key that player is pressing tho, and only if their in the seat?

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)

I’d recommend looking into Context Action Service or User Input Service which can only be used in local scripts.
ContextActionService | Documentation - Roblox Creator Hub

im using it in a normal script, should i use a local script???

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.

it does not work, probably because its in a part.
how can i fix that

Make sure the Local Script is palced in StarterGui and for the part’s variable set its current location in workspace

why should i put it in starter gui?
its not gui…

If the script is a LocalScript and you want it to execute client-side logic, you should place it in StarterGui or StarterPlayerScripts

Learn more about Local Scripts in the documentation:

its not working when i place it in either, i also did change the directory for the seat

Could you provide me your current version of the script?

its the same but i changed this:
local seat = script.parent.seat
to this:
local seat = game.Workspace:WaitForChild("Seat"):WaitForChild("Seat")

i just pressed space and it worked, but its not detecting WASD

actually is ONLY detecting space

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

i just realized, ur only detecting for space… i want to detect for all key presses

then listen for InputBegan event instead of binding to a specific key.