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
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.