Proximity prompt wont get Disabled through code!

So what im trying to achieve is that if u turn into a morph, it checks if ur either on the ‘hunter’ or the ‘Ghosts’ team. if ur on the Ghosts team the prompts should be disabled, and if ur on the Hunter team it should be enabled.

I’ve tried looping through the players, then fire a remote on which team they are and then enable/disable the prompt through a local script. But what happens right now is that the prompt will stay enabled no matter what, it just doesnt disable for the ghosts team.

Ill provide the code below, hoping someone can help?

The morph (SERVER!) script:

local teams = game:GetService("Teams")
local replicatedstorage = game:GetService("ReplicatedStorage")

local model = script.Parent
local prompt = model.Green_Pot_Big_Prompt.ProximityPrompt
local CatchPrompt = model.Green_Pot_Big_Character.Green_Pot_Big.CatchPrompt

local CatchPromptCreateRemote = replicatedstorage.Remotes.CatchPromptCreateRemote

prompt.Triggered:Connect(function(player)
	print("Prompt has been triggered succesfully!") -- to test if its working
	local oldCharacter = player.Character
	local newCharacter = model.Green_Pot_Big_Character:Clone()
	
	newCharacter.HumanoidRootPart.Anchored = false
	newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)
	
	oldCharacter:Destroy()
	newCharacter.Name = player.Name
	player.Character = newCharacter
	newCharacter.Humanoid.HipHeight = 0.5
	newCharacter.Green_Pot_Big.Transparency = 0
	newCharacter.Parent = workspace
	
	CatchPrompt.ActionText = "Catch!"
	CatchPrompt.RequiresLineOfSight = false
	CatchPrompt.HoldDuration = 3
	CatchPrompt.Enabled = false
	
	for i,v in ipairs(game:GetService("Players"):GetChildren()) do
		if v.Team == teams["Hunters"] then
			CatchPromptCreateRemote:FireClient(v, "Hunters")
		elseif v.Team == teams["Ghosts"] then
			CatchPromptCreateRemote:FireClient(v, "Ghosts")
		end
	end
end)

The disabling/enabling the prompt (LOCAL!) script

local replicatedstorage = game:GetService("ReplicatedStorage")
local remote = replicatedstorage.Remotes.CatchPromptCreateRemote
local CatchPrompt = script.Parent

remote.OnClientEvent:Connect(function(v)
	if v == "Hunters" then
		CatchPrompt.Enabled = true
		print("Enabled")
		if v == "Ghosts" then
			CatchPrompt.Enabled = false
			print("Disabled")
		end
		
	end
end)

you’re sending two arguments, maybe try adding in your local script after your v argument like, team or something

remote.OnClientEvent:Connect(function(v, pteam)
	if pteam == "Hunters" then
		CatchPrompt.Enabled = true
		print("Enabled")
		if pteam == "Ghosts" then
			CatchPrompt.Enabled = false
			print("Disabled")
		end
		
	end
end)

Is the Server side morph script working? Also, maybe try using elseif instead of placing the “if v == “Ghosts”” inside of your other if statement. For example (LocalScript):

local replicatedstorage = game:GetService("ReplicatedStorage")
local remote = replicatedstorage:WaitForChild("Remotes"):WaitForChild("CatchPromptCreateRemote")
local CatchPrompt = script.Parent

remote.OnClientEvent:Connect(function(v)
	if v == "Hunters" then
		CatchPrompt.Enabled = true
		print("Enabled")
	 elseif v == "Ghosts" then
			CatchPrompt.Enabled = false
			print("Disabled")
	
		
	end
end)
1 Like

Well i guess im just a bit of a dum dum sometimes, because ofcourse i need to use elseif

This fixed it, thanks!

No problem! :slight_smile:

And you aren’t a dum dum :grin: we all make mistakes sometimes, glad it’s fixed!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.