Hello, My name is Mpire, and I tried to make this script for a shop gui. local gui = script.Parent.ShopGui wait(1) script.Parent.Touched:Connect(function(hit) local PlrName = hit.Parent.Name local Plr = game.Players.PlrName local clone = gui:Clone() clone.Name = "ShopClone" clone.Parent = Plr.Playergui
end) I am somewhat advanced at scripting, and i've been doing this for a long time, and i took a 8 month break from roblox, and now all of a sudden, this doesn't work... And here's the error " 13:11:30.584 - PlrName is not a valid member of Players "
local gui = script.Parent.ShopGui wait(1) script.Parent.Touched:Connect(function(hit) local PlrName = hit.Parent.Name local Plr = game.Players.PlrName local clone = gui:Clone() clone.Name = "ShopClone" clone.Parent = Plr.Playergui end)
All the other answers are bad, and there may be many mistakes.
Try this script:
local Gui = script.Parent:WaitForChild("ShopGui") script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then --Checks if hit parent is player(not part or brick) local Char = hit.Parent local Player = game:GetService("Players"):GetPlayerFromCharacter(Char) local ClonedGui = Gui:Clone() ClonedGui.Parent = Player:WaitForChild("PlayerGui") ClonedGui.Name = "Cloned" --Your cloned gui name here end end)
So here is your script. I will explain your errors.
local Gui = script.Parent.ShopGui wait(1) script.Parent.Touched:Connect(function(hit) local PlrName = hit.Parent.Name local Plr = game.Players.PlrName local clone = gui:Clone() clone.Name = "ShopClone" clone.Parent = Plr.Playergui end)
P.s I am sorry for my bad english.
You can't use .PlrName
when looking for a specific player, in fact, you can't use any variables after a dot. To reference a variable, you must use square brackets. That would make your script look like this:
local gui = script.Parent.ShopGui -- took out the wait, as it wasn't necessary script.Parent.Touched:Connect(function(hit) local PlrName = hit.Parent.Name local Plr = game.Players[PlrName] local clone = gui:Clone() clone.Name = "ShopClone" clone.Parent = Plr.Playergui end)
Another useful thing that square brackets can do is reference models with spaces in their name. This can be very helpful and I suggest you keep it in mind. An example of this would be if you were making a tycoon and added a coal dropper. If you wanted to name it coal dropper with a space to make it look neater in your eyes, you could, it would just require a different code.
Hope I helped. -Cmgtotalyawesome
I think the reason for the error is that studio is now subjected to Filtering Enabled due to the accurate studio update and that you are trying to look for a string that is a child of game.Players rather than a player object. You could have done this to avoid the error by doing:
local plrName = hit.Parent.Name local plr = game.Players[plrName] --or use find first child local plrName = hit.Parent.Name local plr = game.Players:FindFirstChild(plrName)
Correct me if I'm wrong but I think you are using a server script, which is fine, but you can easily achieve the same goals by using a local script.
--I placed this local script inside the shopGUI local plr = game.Players.LocalPlayer workspace.ShopPart.Touched:Connect(function(hit) if hit and hit:IsDescendentOf(plr.Character) then local shopFrame = script.Parent.Frame shopFrame.Visible = true end end)
you can have the gui inside the starter gui and there really isnt any need for cloning as long as you have one frame that encompasses every other GUI element of the shop gui
Hi, is the gui an actual GUI ? if so i Would say you need to do a clicked event, like MouseButton1Down:Connect
touched event is if the actual characters body part was to touch it, or another part for that matter. Let me know! I've never known to use a touched event for a gui
you gotta do this bcz u diddnt add LocalPlayer
local gui = script.Parent.ShopGui wait(1) script.Parent.Touched:Connect(function(hit) local PlrName = hit.Parent.Name local Plr = game.Players.LocalPlayer.PlrName local clone = gui:Clone() clone.Name = "ShopClone" clone.Parent = Plr.Playergui end)
if it still wrong dm me