Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

###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)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.