Hey WHITEHH,
There are a number of problems with your script. They are:
- Lack of indentation. Whenever you make a new code block of any kind (
if, while, do, etc.) you should always increase indent within that block. Extra indentation aids in code readability. Having added some indentation, this is what your script looks like:
PlayerP = game.Players.LocalPlayer
function Click()
game.ServerStorage.THENAMEOFCHARACTER.Shirt:Clone()
game.ServerStorage.THENAMEOFCHARACTER.Shirt:Clone().Parent = workspace.PlayerP
end
script.Parent.MouseButton1Down:connect(Click)
Use of the connect function. This is deprecated, which means it is no longer recommended to use and may one day stop working. Use Connect instead.
Apparently there's something of the same name of the player in ServerStorage? Do yourself a favor and just store the shirt you want directly under ServerStorage.
Assigning the player object to PlayerP. game.Players.LocalPlayer is not a string, it's the actual player object. To get the name of the player, you'd want to write game.Players.LocalPlayer.Name. Additionally, if PlayerP were a string, game.Workspace.PlayerP would not work at all. To achieve the effect you want, use game.Players.LocalPlayer.Character.
Attempt to react to GUI events from a server script. Based on your saying "Should I make this local script btw?" I'm going to assume this is a server script. You should never use a server script to do client-side things (things that only happen in a particular player's game.) Local scripts are meant to do things on a player-by-player basis. If you're doing things like updating a player's GUI, there is no reason to use a server script.
Attempt to access ServerStorage from a local script. Having converted our script to a local script, we now have to change a player's shirt and have that change show for everyone else. This, by contrast to responding to GUI input, is something that the server should do. Therefore, we must make a separate server script to handle this. It should look something like this:
local AddShirtEvent = Instance.new("RemoteEvent")
local Shirt = game.ServerStorage:WaitForChild("Shirt")
local function OnAddShirtEvent(player)
local newShirt = Shirt:Clone()
newShirt.Parent = player.Character
end
AddShirtEvent.Name = "AddShirtEvent"
AddShirtEvent.Parent = game.ReplicatedStorage
AddShirtEvent.OnClientEvent:Connect(OnAddShirtEvent)
To tell the server to add the shirt, we simply change the local script to look like this:
local AddShirtEvent = game.ReplicatedStorage:WaitForChild("AddShirtEvent")
local function OnButtonClicked()
AddShirtEvent:FireServer()
end
script.Parent.MouseButton1Click:Connect(OnButtonClicked)
With all that being said, you might want to check out NoahWillCode's Clean and Tidy, as well as this forum post by yours truly. You really ought to flesh out your knowledge of Lua, as this six line script your posted has more fundamental problems than a square wheel. Hate to say it, but that's just the truth. -_-
Have a nice day, WHITEHH, and best of luck learning Lua.
Truly yours,
tkcmdr
Resources:
RBXScriptSignal Wiki Page
Player Wiki Page
FilteringEnabled and Client-Server relationship guide
Remote Event Wiki Page
WaitForChild Wiki Page
ServerStorage Wiki Page
ReplicatedStorage Wiki Page
1 comment
It's not taking the shirt into the players body. And proably should be a Local Script. If you wan't me to help the comment.