Proximintyprompt won't stay disabled (local)

I’ve tried this method and then got this error “attempt to index nil with ‘Character’” inside of my local script.

I could just try to post the game so people could have a look at it themselves if that would makes things easier? And it would truly help me a lot

So pass the player argument in the FireClient part, but don’t use it in the event part. Instead, use the character variable you made beforehand.

That should work! :slightly_smiling_face:

You should add a value to the PlayerObject telling us if the prompt should be enabled or not.

Something like this right?


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

It did work, but I’m getting the same result, it only works when the player first joins the game, then when the player resets, the proximintyprompt stays enabled. :sob:

You should not use a RemoteEvent for this as they lag the game, and this is such a simple task, it would be better to toggle a value.

You cannot get the LocalPlayer from the server, you should add a playeradded and listen until the local player is added.

How could you listen for when a local player is added do I do something like this?


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

I’m not the best scripter I am learning from youtube tutorials and roblox dev, that’s how I even managed to get at least to this point. Sorry if I don’t fully understand everything, I am willing to learn

You should use the RBXScriptConnection feature for your scripts, it allows you to do this:

game.Players.PlayerAdded:Connect(function(player) -- the player argument returns the player that was added

end)

Thanks for the advice, but I just noticed I’m not using the “client” variable anyway for what I’m doing. It was there by mistake cause of something else I was doing. Is it actually needed for my server script to be able to work because properly because without the client variable anyway the script did work just broke once the player restarted.

Also your method was great I saw it before you took it down, but once the player restart, the other now can’t see it anymore. This is a never ending nightmare. :ghost:

Yeah, I realized that after I posted it, haha. Just give me a couple minutes, I’ll have a working script for you.

If you could manage thank you a lot. Hopefully it will work, I could learn a lot from this experience from where I went wrong.

Sorry I went to go eat, anyways. My theory is that for whatever reason the script is referencing the old character rather than the new character that gets spawned. That’s the only thing I can think of that would match up with the errors you’re talking about. Try this and let me know how it works.

Server

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



local function createUI(player, character)
	local newProximityPromt = proximityPrompt:Clone()
	newProximityPromt.Parent = character
	newProximityPromt.ActionText = "Contact!"
	newProximityPromt.ObjectText = character.Name
	newProximityPromt.RequiresLineOfSight = false
	newProximityPromt.Enabled = true
	HideProximity:FireClient(player)
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		createUI(player, character)
	end)
end)

Client

local player = game.Players.LocalPlayer

local function Hide()
	local character = workspace:WaitForChild(player.Name)
	local prox = character:WaitForChild("ProximityPrompt")
	prox.Enabled = false	
		
end

game.ReplicatedStorage.HideProximity.OnClientEvent:Connect(Hide)
2 Likes

THANK YOU SOO MUCH! It works like a charm, I’ll defintely look to see where I went wrong compared to your script even though I’m pretty sure like you said it was probably referring to the old proximityprompt. Still thanks a lot! :hugs:

2 Likes