Fatal error on my script of disabling ProximityPrompts

Hello again, it has been a long time since i made a script when you sit in any of the seats on the car, the proximity prompts disappear for better visibility, something i didnt realize is that makes all the players dont see the proximity prompt, so when you sit on any seat, driver seat or the passenger seat, nobody cant enters on the car unless you leave.

I think theres nothing to explain no more and any doubts you can ask

Heres the script

server script inside the proximity prompt

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		proximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = false
	else
		proximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = true
	end
end)

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid.Sit == false then
		seat:Sit(player.Character.Humanoid)
	end
end)
1 Like

Have you tried using a local script and getting the LocalPlayer?

1 Like

yes i tried and it stopped working, i used that remote events and stuff

because as far as i know you cant use with local script

oh and i forgot saying that i tried making a localscript on the startercharacterscripts

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character.Humanoid

for _, seats in pairs(workspace.Vehicles:GetDescendants()) do
	if seats.ClassName == "Seat" or "VehicleSeat" then
		if seats.Occupant == nil then
			seats.Parent.ProximityPrompt.Enabled = true
		end
	end
end
1 Like

ProximityPrompts are located in the Player’s PlayerGui.
image
You can just make the Enabled property of the BillboardGui false.

i dont think that would work because disabling them would still be disabling them to everyone, theres not a way to make them only disappear to the person that is sitting?

1 Like

It will work. Every player has their own PlayerGui folder. Whenever you do something to that folder, only the player will see it.

i think that would work but somethings wrong with detecting the humanoid, ive been having this problems since yesterday, everytime i try to locate the humanoid it says attempt to index nil with humanoid

local player = game.Players.LocalPlayer

local character = player.Character

local humanoid = character.Humanoid

if humanoid.Sit == true then

for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do

proximityPrompts.Enabled = false

end

else

for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do

proximityPrompts.Enabled = true

end

end

somethings wrong with the prefformated text too lol

I think the script is running before the player’s character has loaded. Try this instead:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharcterAdded:Wait()
local humanoid = character.Humanoid

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	if humanoid.Sit == true then
		for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do
			proximityPrompts.Enabled = false
		end
	else
		for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do
			proximityPrompts.Enabled = true
		end
	end
end)
1 Like

ahh how i love roblox

image

Try local humanoid = character:WaitForChild("Humanoid") instead.

now its saying that proximityprompts dont exist

image

I think I know the problem, the game doesn’t create the ProximityPrompts ScreenGui until you see one for the first time. Try this:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharcterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local FoundPrompts = false

player.PlayerGui.ChildAdded:Connect(function(Child)
	if Child.Name == "ProximityPrompts" then
		FoundPrompts = true
		for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do
			proximityPrompts.Enabled = false
		end
	end
end)

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	if FoundPrompts == true then
		if humanoid.Sit == true then
			for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do
				proximityPrompts.Enabled = false
			end
		else
			for _, proximityPrompts in pairs(player.PlayerGui.ProximityPrompts:GetChildren()) do
				proximityPrompts.Enabled = true
			end
		end
	end
end)

yea now no problems on the output but when you are sitting on the car the proximity prompts still appear

Alright, I decided to just make the ScreenGui disabled.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharcterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local FoundPrompts = false

player.PlayerGui.ChildAdded:Connect(function(Child)
	if Child.Name == "ProximityPrompts" then
		FoundPrompts = true
		player.PlayerGui.ProximityPrompts.Enabled = false
	end
end)

humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	if FoundPrompts == true then
		if humanoid.Sit == true then
			player.PlayerGui.ProximityPrompts.Enabled = false
		else
			player.PlayerGui.ProximityPrompts.Enabled = true
		end
	end
end)

so it didnt work, but i tried disabling the screengui by myself just to test, and even disabled, the proximityprompts dont appear lol

if instead of this, script to when the humanoid is sitting, take all the descendents of the vehicle, and if its a proximity prompt, disable it all, and when you not sitting enable it again, should it work?

That would still hide it from all of the players.

so… theres no way of hiding it just for the player sitting?

1 Like

I’m trying to figure out a way right now.