Proximity Prompt Morph Accessories

  1. What do you want to achieve? I want to achieve Proximity Prompt that lets the player wear an morph accessory.

  2. What is the issue? This probably sounds like an excuse. My head is filled with so much stress that I struggle with the code and I barely know what to do anymore.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tried to search YouTube tutorials and I still don’t get it. I haven’t seen a Developer Hub post about something like this here. The only closest thing at least I think was this post: Morph Kit Thing - Help and Feedback / Creations Feedback - DevForum | Roblox

I suck at coding and sometimes I barely know what I am supposed to do. I know this isn’t the place where you ask for code.

function onTouched(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Lantern") == nil then
		local g = script.Parent.Parent.Lantern:clone()
		g.Parent = hit.Parent
		local C = g:GetChildren()
		for i=1, #C do
			if C[i].className == "UnionOperation"or C[i].className == "Part" then
				local W = Instance.new("Weld")
				W.Part0 = g.Middle
				W.Part1 = C[i]
				local CJ = CFrame.new(g.Middle.Position)
				local C0 = g.Middle.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.Middle
			end
				local Y = Instance.new("Weld")
				Y.Part0 = hit.Parent.Torso
				Y.Part1 = g.Middle
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			h[i].Anchored = false
			h[i].CanCollide = false
		end
		
	end
end

script.Parent.Touched:connect(onTouched)

This is the code I have been trying to change. I have 3 scripts that are used.

function onTouched(hit) 
	local d = hit.Parent:GetChildren() 
	for i=1, #d do 
		if (d[i].className == "Hat") then 
			d[i].Handle.Transparency = 1
		end 
	end
end 

script.Parent.Touched:connect(onTouched)
function onTouch(part) 
local human = part.Parent:findFirstChild("Humanoid") 
if human ~= nil then 
part.Parent:findFirstChild("Head").Transparency = 1
part.Parent:findFirstChild("Torso").Transparency = 1
part.Parent:findFirstChild("Left Arm").Transparency = 1
part.Parent:findFirstChild("Right Arm").Transparency = 1
part.Parent:findFirstChild("Left Leg").CanCollide = true
part.Parent:findFirstChild("Left Leg").Transparency = 1
part.Parent:findFirstChild("Right Leg").CanCollide = true
part.Parent:findFirstChild("Right Leg").Transparency = 1
end 
end 
script.Parent.Touched:connect(onTouch)

I’m sorry for being stupid.

Stop self deprecting lmao.

What is going wrong with the code, track down what events are firing and where errors happen.

we arent going to fix your script for you, but we will give you guidance in what is wrong

  1. Make a part
  2. Add a proximity prompt to it
  3. Put the script in the proximity prompt
  4. Replace .Touched wherever you have it with script.Parent.ProximityPrompt.Triggered:Connect(onTouched)

Bro… How he gonna learn how to debug if you just tell him what is wrong.

Ur right tho but still.

Quite frankly, there is nothing major to debug. He isn’t an experienced programmer and is still learning how things work so obviously didn’t expect him to know how to trigger a proximity prompt.

It’s only about two words that had to be replaced.

1 Like

Ok then.
Maybe you right.

Still should’ve said something like “you aren’t triggering a proximity prompt, you are using .Touched”.

1 Like

Seems like the solution but I am probably too stupid and didn’t do it correctly

Using proximity prompt service, you can detect whenever a proximity prompt is activated. Then, you check if it is the prompt you are trying to detect, and run the code if it is.

(the example they give is below)

local ProximityPromptService = game:GetService("ProximityPromptService")

-- Detect when prompt is triggered
local function onPromptTriggered(promptObject, player)

end

-- Detect when prompt hold begins
local function onPromptHoldBegan(promptObject, player)

end

-- Detect when prompt hold ends
local function onPromptHoldEnded(promptObject, player)

end

-- Connect prompt events to handling functions
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
ProximityPromptService.PromptButtonHoldBegan:Connect(onPromptHoldBegan)
ProximityPromptService.PromptButtonHoldEnded:Connect(onPromptHoldEnded)

In this example, we fire function “onPromptTriggered” when ANY prompt is triggered.
There are two parameters to the function “onPromptTriggered,” which are the prompt that was triggered (Instance), and the player who did it.

Make sure the script is in the proximity prompt (place this script under the proximity prompt). The parent of the script should be the proximity prompt.

under
It is in the proximity prompt

If we want to see when the prompt gets triggered, the code would look something like this.

local function onPromptTriggered(promptObject, player)
    if promptObject == script.Parent then -- Check if the activated prompt is the one we are looking for (the script's parent)
        print(player) -- this should print the player instance of the person who activated it
    end
end

ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)

Why is there a proximity prompt in the head or it’s trying to index Proximity prompt inside of another proximity prompt.

Not the player head, the part is just called head. I tried making a part and adding a proximity there but it did the same result.

Ah I see the error. Just do script.Parent instead of script.Parent.ProximityPrompt.

Or just place the script outside the proximity promt but under the parent of the proximity prompt.

If the script is under the proximity prompt, this script should detect it being activated.

Yep it detects it.
detect

1 Like

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