Proximity Prompt Help

Salutations developers! I need help in scripting this drinking system I’m currently working on. I wanted it to adapt the ProximityPrompt feature. I made a little script, apologies as I’m new but there are errors in it.

1 Like

Well you can not do “inv.Parent” etc because your inv variable is just a string “Cup”. To fix it just change

local inv = "Cup"

with path to your cup

How in any way? I apologize as I’m new to scripting.

Where is your cup placed in explorer?

My cup is placed in the ServerStorage.

Isn’t :FindFirstChildWhichIsA used to detect an instance with a certain Class, not name? You should use :FindFirstChild() instead, which is used to find the names of a certain instance.

Also, please try your best to copy and paste your code onto the DevForum. Include a ``` at the start of your code to format it properly here.

Oh, now I know. Attempting to apply it right now. Hope it works!

Oh, I get this now. So it must be:

local inv = game.ServerStorage["Cup"]

If you’re planning to do this, you’ll have to replace the line:

if Player.Character:FindFirstChild(inv) then

To this:

if Player.Character:FindFirstChild(“Cup”) then

This is because FindFirstChild uses a string to find the specified Instance.

Update: Changed it to :FindFirstChild() and it works. The only things is that the name of the Cup doesn’t change to “Frappe”.

It was working when I didn’t add the path and replaced (inv) with (Cup). The only issue is that it doesn’t change to Frappe.

Are you able to send in a full revision of your script currently? It’s slightly confusing when I’m not sure what you’re editing exactly.

Sure! Here you go:

local prompt1 = script.Parent.ProximityPrompt
local inv = "Cup"

prompt1.Triggered:Connect(function(Player)
	if Player.Character:FindFirstChild(inv) then
		script.Sound:Play()
		wait()
		script.Parent.Parent.Drip.Transparency = 0
		wait(3)
		script.Parent.Parent.Drip.Transparency = 1
		inv.Parent.Drink.BrickColor = BrickColor.new(255, 204, 153)
		inv.Parent.Drink.Material = "SmoothPlastic"
		inv.Parent.Drink.Transparency = 0
		inv.Parent.Name = "Frappe"
	end
end)

That’s the revisioned script.

Perhaps, try to create a variable for this when you find inv in the Player’s Character:

local userCup = Player.Character.Cup -- We can safely point to the tool named “Cup”, since we know that the Scripts checks for the tool’s name in the Player’s Character.

And when you edit the properties for the Cup, just replace inv.Parent with userCup. As inv is pointing to a string, you therefore are not able to change the property of the tool in the Player’s inventory. (As mentioned by @Skiilguard .)

Like this??

local prompt1 = script.Parent.ProximityPrompt
local usercup = Player.Character.Cup

prompt1.Triggered:Connect(function(Player)
	if Player.Character:FindFirstChild(usercup) then
		script.Sound:Play()
		wait()
		script.Parent.Parent.Drip.Transparency = 0
		wait(3)
		script.Parent.Parent.Drip.Transparency = 1
		usercup.Parent.Drink.BrickColor = BrickColor.new(255, 204, 153)
		usercup.Parent.Drink.Material = "SmoothPlastic"
		usercup.Parent.Drink.Transparency = 0
		usercup.Name = "Frappe"
	end
end)

No, let me break it down for you.

You would only place usercup in the script where it’s checking for the Player’s Character. FindFirstChild would only support strings.

local prompt1 = script.Parent.ProximityPrompt

prompt1.Triggered:Connect(function(Player)
	if Player.Character:FindFirstChild(“Cup”) then -- We are checking if there is something named “Cup” in the Player’s Character - which would be the tool!
        local usercup = Player.Character.Cup -- This is because we need to confirm that “Cup” is an actual instance in the Player’s character first, before we set this variable.
		script.Sound:Play()
		wait()
		script.Parent.Parent.Drip.Transparency = 0
		wait(3)
		script.Parent.Parent.Drip.Transparency = 1

        -- We need not search for the Parent for this. As usercup points to the tool instance, not some random part in the tool, we do not need to place “.Parent” here.
		usercup.Drink.BrickColor = BrickColor.new(255, 204, 153)
		usercup.Drink.Material = "SmoothPlastic"
		usercup.Drink.Transparency = 0
		usercup.Name = "Frappe"
	end
end)

Oh that’s why I’m getting the blue underline in the player. I should’ve put it under the trigger function. Now it works, I can finally finish my cafe thanks to your help! <3

1 Like

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