How to change tool's name using ProximityPrompt

So, I’m trying to make it when you’re holding the tool out and holding ‘E’ on your keyboard it will change the tool’s name. I tried scripting it, but it didn’t work. Can anyone help me find out what’s wrong?

local button = script.Parent

local CurrentName = "Cup" 
local NewName = "Espresso"

button.Triggered:Connect(function(t)
	if t.Parent.Name == CurrentName then
		t.Parent.Name = NewName
	end
end)
1 Like

Triggered returns the Player who triggered it so. You need to search the players character for the correct tools name and check it’s a tool.

2 Likes

I am new to scripting, so I don’t know what you mean

This is what they mean:

local button = script.Parent

local CurrentName = "Cup" 
local NewName = "Espresso"

button.Triggered:Connect(function(t)
    if not t.Character then -- this checks if the player didn't die or something
       return
    end

	local obj = t.Character:FindFirstChild(CurrentName) -- search for the object in the player's character

    if obj and obj:IsA("Tool") then --this checks if the tool exists
        obj.Name = NewName -- set the new name
    end
end)

So, I tested out the script and it didn’t work

Did you get any errors? Did you have it equipped? The script only works if it’s equipped. For it it to check if it exists in the player’s backpack, you would have to do this:

local button = script.Parent

local CurrentName = "Cup" 
local NewName = "Espresso"

button.Triggered:Connect(function(t)
    if not t.Character then
       return
    end

	local obj = t.Character:FindFirstChild(CurrentName) or t.Backpack:FindFirstChild(CurrentName) -- this checks both the backpack and the character

    if obj and obj:IsA("Tool") then
        obj.Name = NewName
    end
end)

Make sure this is in a server script and not a local script

I equipped the tool, but still didn’t work. Here’s a screen shot of the error (not sure if this will help):

image

There’s the issue, your script isn’t referencing the proximity prompt, it’s referencing the proximity prompt’s parent.

Change the button variable to the Proximity Prompt

1 Like

Alright! It worked! Thanks for helping me!

1 Like