Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago

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

0
Note: the error is for the 10th line which is what renames the remote CheeseBallGuy11 12 — 2y

3 answers

Log in to vote
0
Answered by 2 years ago

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!

Ad
Log in to vote
1
Answered by 2 years ago

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

Log in to vote
0
Answered by
ym5a 52
2 years ago
Edited 2 years ago

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.

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. CheeseBallGuy11 12 — 2y
0
So just use Player.Character.Name right? ym5a 52 — 2y
0
I'm getting the players name fine, I'm just not sure how to rename the remote event as it now CheeseBallGuy11 12 — 2y

Answer this question