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

Is there anyway to run seat.Changed or something similar on a local script?

I need to run a script when a seat that is copied locally has a player seated.

1 comment

0

Maybe I didn't word that the best. What I meant was. There's a seat that is copied by a local script from ReplicatedStorage and this seat needs to detect when a player is seated so then fires to the server for certain actions.

1 answer

There certainly is. The way to do this, is everytime the seat changes, check the if the seat occupant is equal to the character Humanoid.


local plr = game.Players.LocalPlayer -- get the player
local chr = plr.Character or plr.CharacterAdded:Wait() -- get the character, if its not there then wait.
local humanoid = chr:WaitForChild("Humanoid") -- wait for the character humanoid

local seat = game.Workspace:WaitForChild("SeatName") -- wait for the seat

seat.Changed:Connect(function() -- when seat changes, perform this function
	if seat.Occupant == humanoid then -- if the humanoid is in the seat, run this code
		-- do whatever when they sit in it.
	end
end)

I hope this helps!

2 comments

0

when i did seat.Changed for a local script it didn't seem to work

0

thats because localscripts only run either; under replicatedfirst, playergui, backpack, player character or playerscripts.

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