Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can localscripts rename objects and if so how come mine isn't?

I'm trying to rename a RemoteEvent from a localscript in playergui which is activated by a key press but I get the error message "invalid argument #3 (string expected, got Instance)" from this bit of code:

local Player = game:GetService("Players").LocalPlayer.Name
local Playeruse = game.Workspace:WaitForChild(Player)
if Playeruse:FindFirstChild(Player) == true then
	print(Playeruse)
end

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Remote")
remoteEvent.Name = Playeruse

Someone please help me

1 comment

0

Note: the error is for the 10th line which is what renames the remote

3 answers

✓ Accepted answer

Object names are meant to be in strings, so you should add speach marks:

Heres the adjusted script:

local Player = game:GetService("Players").LocalPlayer.Name
local Playeruse = game.Workspace:WaitForChild(Player)
if Playeruse:FindFirstChild(Player) == true then
    print(Playeruse)
end

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remoteEvent = ReplicatedStorage:WaitForChild("Remote")
remoteEvent.Name = "Playeruse"

Hope this helped!

Any Questions? Just ask!

Local scripts CAN rename objects, but only for the client. This means that for other players and server scripts, the name will not change,

Instead of using "game.Workspace:WaitForChild(Player)"

Just do "Player.Character" If you are trying to get the players character. The script is failing because you are waiting for a LocalPlayer which are only found in Players, not workspace. Thus indexing nil and returning an Instance Oh, and I dont think localscripts can change names.

3 comments

0

That wasn't the issue, I got it to get the players name now and can get the script to rename the remote event with any text but how do I get it to rename with the players name? If I use Playeruse which is the players name I get the same error again.

0

So just use Player.Character.Name right?

0

I'm getting the players name fine, I'm just not sure how to rename the remote event as it now

This discussion is preserved as it was. New answers, comments, and votes are closed.