Server Replication Issue?

So Im trying to disable a proximity prompt for a certain player, but then i came across the great attempt index nil error. I am confused by why this occurs as it was cloned by the server itself

server:

print(prox) -- ProximityPrompt
game:GetService('ReplicatedStorage').EnablePrompt:FireClient(player, prox, false)

client:

local UserInputService = game:GetService('UserInputService')

game.ReplicatedStorage.EnablePrompt.OnClientEvent:Connect(function(prompt, state)
	print(prompt, state) -- nil false
	prompt.Enabled = state
end)
2 Likes

If its a clone, the client won’t be able to access it until its in an area that the client has access to.

1 Like

Can you show us the origin of the prox from the server.

Did you put the proximity in workspace before sending the fireEvent?

Its in the player’s humanoid root part, is that accessable to the client?

Yeah i did parent it to the workspace

Does the server recognize the ProximityPrompt or is it just the client?

As i mentioned on the original post, yes the server does recognize it

Where did the error come from?

Oh nvm its from the client.

So which one is the nil, is it the prompt, or state? I’m guessing it’s from the prompt.

Yeah, its the prompt thats nil, the state itself is intact

Please let me see how you cloned the Prompt and such.

Can you print the full name of the prox with the server script.

local prox = script.Arrest:Clone()
prox.Parent = character.HumanoidRootPart
		
prox.ActionText = 'Arrest'
prox.ObjectText = player.Name
		
print(prox)
game:GetService('ReplicatedStorage').EnablePrompt:FireClient(player, prox, false)

Says Artzified.HumanoidRootPart.Arrest

The reason why it’s a nil it’s because on the client side the ProximityPrompt is a nil meaning it does not exist yet.

Try adding a wait for a few seconds and check if you would still receive the error.

2 Likes

Try this. I cleaned up some of your variables.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EnablePrompt = ReplicatedStorage:WaitForChild("EnablePrompt")
local Prox = script:WaitForChild("Arrest") -- Keep this outside of your function

-- Inside of your function
local HumanoidRootPart = Character:FindFirstChild("Humanoid")
if HumanoidRootPart then
	local prox = Prox:Clone()
	prox.Parent = character.HumanoidRootPart
		
	prox.ActionText = 'Arrest'
	prox.ObjectText = player.Name

	EnablePrompt:FireClient(player, prox, false)
end
--Clientside
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EnablePrompt = ReplicatedStorage:WaitForChild("EnablePrompt")

EnablePrompt.OnClientEvent:Connect(function(prompt, state)
	print(prompt, state) -- nil false
	if prompt then
		prompt.Enabled = state
	end
end)
1 Like

Ah, i see. Thanks for your time!

1 Like

If you wish to go for the wait approach, I would suggest going for something like this on the clientside, instead of adding a wait on the server.

EnablePrompt.OnClientEvent:Connect(function(character, promptName, state)
	local prompt = character:WaitForChild("promptName")
	prompt.Enabled = state
end)

From the server, you instead send the character, and the name of the prompt, along with the state.

Edit: And if you wish to go full-secure, make the prompt waiting on the client into a pcall, so if it fails, it doesn’t error.

1 Like