When the player is seated, the proximity prompt inside the seat will be turned off or disabled. However, it happens to all players, even if they are not seated. I’d like to make the scripts happen only for a specific player. I attempted to make a few changes to my script, but it didn’t work well. At this point, it’s like I’ve reached a dead end in a maze… again. Tell me, where did I go so wrong?
The RemoteEvent is in “ReplicatedStorage” inside a folder named “Events”
The local script that fires the even is in “StarterCharacterScripts”
The Script Code:
local lp = game.Players.LocalPlayer
local event1 = game.ReplicatedStorage.Events.PlayerIsSeated
local event2 = game.ReplicatedStorage.Events.PlayerIsNotSeated
local humanoid = script.Parent.Humanoid
humanoid.Changed:Connect(function(Property)
if Property == "Sit" then
if humanoid.Sit == true then
event1:FireServer()
end
end
end)
humanoid.Changed:Connect(function(Property)
if Property == "Sit" then
if humanoid.Sit == false then
event2:FireServer()
end
end
end)
Set the .Enabled property on the client for that specific player(basically there’s no need to use RemoteEvents since they’re setting .Enabled on the server and therefore cause the issue):
--other references(LocalScript)
local humanoid = script.Parent.Humanoid
local prompt = PathToSeat.Seat.Attachment.ProximityPrompt
humanoid.Changed:Connect(function(property)
if property == "Sit" then
prompt.Enabled = (not humanoid.Sit)
end
end)
--LOCAL
local Replicated = game:GetService("ReplicatedStorage")
local Events = Replicated:WaitForChild("Events")
local IsSeated = Events:WaitForChild("PlayerIsSeated")
local IsNotSeated = Events:WaitForChild("PlayerIsNotSeated")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Seated then
IsSeated:FireServer()
elseif NewState ~= Enum.HumanoidStateType.Seated then
IsNotSeated:FireServer()
end
end)
--SERVER
local Replicated = game:GetService("ReplicatedStorage")
local Events = Replicated.Events
local IsSeated = Events.PlayerIsSeated
local IsNotSeated = Events.PlayerIsNotSeated
local Prompt = script.Parent
IsSeated.OnServerEvent:Connect(function(Player)
Prompt.Enabled = false
end)
IsNotSeated.OnServerEvent:Connect(function(Player)
Prompt.Enabled = true
end)
A couple of issues with your original scripts, first of all you can use the “StateChanged” event of the Humanoid instance instead of the “Changed” event as the “StateChanged” event will only fire when the humanoid’s internal state changes, whereas the “Changed” event is less specific (more vague) and will fire whenever any of the humanoid’s properties change. Secondly, when connecting callback functions to events through use of the connection method “:Connect()” if you connect two or more callbacks to the same event then the last callback function connected will override any other connections made. That’s about it, other than that I’m fetching the humanoid instance in a more reliable manner but that’s just a personal preference.