Adding Proximity Prompts to Players

Hello! I am trying to add an proximity prompt to players, but I don’t know how to do that.
Here is my current script:

local RS = game.ReplicatedStorage
local prompt = RS.ClashPrompt

game.Players.PlayerAdded:Connect(function(plr)
	local newPrompt = prompt:Clone()
	newPrompt.Parent = plr.Character
end)

(Sorry if the script is bad or this is easy to solve, i am still new to Roblox Studio)

change

newPrompt.Parent = plr.Character

to

newPrompt.Parent = plr.Character or plr.CharacterAdded:Wait()
2 Likes

Here’s what I changed: I added a variable for the character, which waits if it is not found, as I noticed that printing the character as the function was fired returned nil (the character didn’t exist yet.)

2 Likes

Yeah, that’s the change I made. Should work, I believe, mark him as solution if it worked.

2 Likes

Thanks for all the help, it worked.

I still have a question, I have this script that makes it so only other players can see the proximity prompt, but it doesn’t seem to work

here is my script:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

char.ChildAdded:Connect(function(child)
	if child:IsA("ProximityPrompt") then
		if child.Parent == char then
			child.Enabled = false
		end
	end
end)

Since the server code runs before the ChildAdded fires in this case, the ChildAdded event is futile. Here’s what I did instead:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local proximityPrompt = char:WaitForChild("ClashPrompt") :: ProximityPrompt -- The :: ProximityPrompt basically says "This IS a proxy prompt"
proximityPrompt.Enabled = false
1 Like

Thank you so much for the help