Proximintyprompt won't stay disabled (local)

I have a remote event that sets the proximintyprompt enabled to be false (locally). The problem is it works when the player first joins the game. I can’t find the reason why when the player respawns it fires my remote event again but doesn’t set the proximintyprompt enabled to false. You could see that I even have a print statement for when it’s triggered and that works, but it doesn’t disable to proximityprompt.

What the problem looks like

[Server]

local replicatedStorage = game:GetService("ReplicatedStorage")
local HideProximity = replicatedStorage:WaitForChild("HideProximity")


local Players = game:GetService("Players")
local client = Players.LocalPlayer

local proximityPrompt = replicatedStorage:WaitForChild("ProximityPrompt")



local function onCharacterAdded(character)

	if not character:FindFirstChild("ProximityPrompt") then
		local newProximityPromt = proximityPrompt:Clone()
		newProximityPromt.Parent = character
		newProximityPromt.ActionText = "Contact!"
		newProximityPromt.ObjectText = character.Name
		newProximityPromt.RequiresLineOfSight = false
		newProximityPromt.Enabled = true
		HideProximity:FireAllClients(character) 
		
	end
end

local function onPlayerAdded(player)
	if player.Character then
		onCharacterAdded(player.Character)
	end
	-- Listen for the player (re)spawning 
	player.CharacterAdded:Connect(onCharacterAdded)
end

-- Iterate over each player already connected
-- to the game using a generic for-loop
for i, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

-- Listen for newly connected players
Players.PlayerAdded:Connect(onPlayerAdded)

[Local]

local replicatedStorage = game:GetService("ReplicatedStorage")
local HideProximityPrompt = replicatedStorage:WaitForChild("HideProximity")

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local character = player.Character


if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end



local ProxmityPrompt = character:WaitForChild("ProximityPrompt")


local function HideProximity(character)
	ProxmityPrompt.Enabled = false
	print("Got Milk?")

end

HideProximityPrompt.OnClientEvent:Connect(HideProximity)

Note:

I haven’t been scripting for that long and I try my best not to post on the forum unless I really do need the assistance, but I’ve been dealing with this problem for a whole day now. I’ve done plenty of searching, and I couldn’t manage to find anything to fix this problem myself.

2 Likes

ProximityPrompt.Parent = nil

And when you want to bring it back,

ProximityPrompt.Parent = (whatever you want it parented to)

This is a hacky? but easy fix if .Enabled is acting weird.

(in the localscript. If you do it in the server it actually gets rid of EVERYONE’S ability to use the ProximityPrompt.)

Or simply just use

HideProximityPromt.OnClientEvent:Connect(function()
ProxmityPrompt.Enabled = false
print('Got Milk?')
end)

This ties :Connect() directly to the function. You have no typos, unless the variable name was unintentionally named “ProxmityPrompt”, but it will still work.

1 Like

I think it’s because whenever the character is added it deletes the ProximityPrompt and then you clone another ProximityPrompt and you set its Enabled property to true

1 Like

I didn’t realize this. This is probably the problem ^

What you said earlier was true “Proxmityprompt” was a typo, but doesn’t really matter atm since it’s just a variable. But I also do believe what ScriptingIsCool said, but I don’t know how to stop it or what to do

whoops, I removed the enabled = true. however the problem still remains

I’ve tried this and still the same problem keep occurring :confused:

Where is the local script located?

It’s located in StarterPlayerScripts

Try switching it to StarterCharacterScripts and tell me if it works

I’ve done what you said and it still doesn’t work

You moved the local script to the StarterCharacterScripts?

Yeah that’s what I did and it’s still the same sadly

I didn’t quite understand what’s the issue and what do you want to achive

My goal is to make the proximityprompt enable be false (locally). So that the player isn’t able to see their own proximintyprompt.

It thinks you’re passing the function as the parameter of the event. Try this:

local replicatedStorage = game:GetService("ReplicatedStorage")
local HideProximity = replicatedStorage:WaitForChild("HideProximity")


local Players = game:GetService("Players")
local client = Players.LocalPlayer

local proximityPrompt = replicatedStorage:WaitForChild("ProximityPrompt")



local function onCharacterAdded(character)

	if not character:FindFirstChild("ProximityPrompt") then
		local newProximityPromt = proximityPrompt:Clone()
		newProximityPromt.Parent = character
		newProximityPromt.ActionText = "Contact!"
		newProximityPromt.ObjectText = character.Name
		newProximityPromt.RequiresLineOfSight = false
		newProximityPromt.Enabled = true
		HideProximity:FireClient(character) 
		
	end
end

local function onPlayerAdded(player)
	if player.Character then
		onCharacterAdded(player.Character)
	end
	-- Listen for the player (re)spawning 
	player.CharacterAdded:Connect(onCharacterAdded)
end

-- Iterate over each player already connected
-- to the game using a generic for-loop
for i, player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

-- Listen for newly connected players
Players.PlayerAdded:Connect(onPlayerAdded)
local replicatedStorage = game:GetService("ReplicatedStorage")
local HideProximityPrompt = replicatedStorage:WaitForChild("HideProximity")

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local character = player.Character


if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end



local ProxmityPrompt = character:WaitForChild("ProximityPrompt")


local function HideProximity(character)
	ProxmityPrompt.Enabled = false
	print("Got Milk?")

end

HideProximityPrompt.OnClientEvent:Connect(function(char)
    HideProximity(char)
end)

Just to confirm are you trying to make the ProximityPrompt invisible at all times? If so there is an easier way to do so if you just don’t want it to ever be visible, but I’m unsure if you’re attempting to do that.

I used the code you provided above and I get this error "FireClient: player argument must be a Player object " I just copy and pasted.

That is what I’m trying to do but for the local player only, so he’s able to see other people proximintyprompt, but he’s not able to see his own. That’s why I set proximintyprompt enabled to be false in a server script

Stay true to the error!

Use this for the FireClient line:

HideProximity:FireClient(game.Players:GetPlayerFromCharacter(character))

Then this for the retrieved part:

HideProximityPrompt.OnClientEvent:Connect(function(plr)
    HideProximity(plr.Character)
end)