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.
This ties :Connect() directly to the function. You have no typos, unless the variable name was unintentionally named “ProxmityPrompt”, but it will still work.
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
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
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.
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