Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a script that checks what seat the player is on?

Asked by 5 years ago

I'm trying to see if I can make a script that checks what seat the player is on, and if they are on a certain seat it will do something, like change the camera subject or explode something.

This is the code I got:

wait()
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()
local hum = chr:WaitForChild("Humanoid")
hum.Changed:connect(function()
    if hum.SeatPart == "Seat" then
        print("a")
    elseif hum.SeatPart == "CamSeat" then
        workspace.CurrentCamera.CameraSubject = chr.Head
    end
end)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The problem in your code is very simple. The SeatPart property holds an object reference, not a string. So simply add a .Name. Remember to use a LocalScript.

local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait() -- :wait is deprecated 
local hum = chr:WaitForChild("Humanoid")
hum.Changed:Connect(function(prop) -- connect is deprecated
    if prop ~= "SeatPart" then return end -- if the property wasn't the seatpart then end the function

    if hum.SeatPart.Name == "Seat" then
        print("a")
    elseif hum.SeatPart.Name == "CamSeat" then
        workspace.CurrentCamera.CameraSubject = chr.Head
    end
end)
0
Thank you! MeleeSoul 14 — 5y
Ad

Answer this question