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

So im making a GUI change the players shirt(LocalScript) but it doesn't work?

Code is below please help lol

Player = game.Players.LocalPlayer.Character

function click()
	Player.Shirt.ShirtTemplate = 7195910588
end

script.Parent.MouseButton1Click:connect(function() click() end)

also output Players.Kantruzt.PlayerGui.AdminThing.ShirtChanger.Frame1.Shirt6.Script:1: attempt to index nil with 'Character'

1 comment

0
local Player = game.Players.LocalPlayer.Character

function click()
    Player.Shirt.ShirtTemplate = 7195910588
end

script.Parent.MouseButton1Click:connect(click)

Maybe try this

2 answers

✓ Accepted answer

Problem:

Character isn't defined.

Description:

When the game runs, the Player and CharacterModel get inserted into the game. You CANNOT access anything from the character if you don't reference it

Solution:

  • Remember to reference the character
  • Remember to call your function
  • It's better to use :WaitForChild, as the instance, might not be in the game yet.

Recommendations:

When connecting an event to a function, :Connect should be capitalised, as :connect is deprecated.

Fixed Script:

Player = game.Players.LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()

function click()
	character:WaitForChild("Shirt").ShirtTemplate = "http://www.roblox.com/asset/?id=7195910588"
end

script.Parent.MouseButton1Click:Connect(click) 

1 comment

0

Fixed a minor error!

hey there. so in order to make the image of the clothing load, you have to put "rbxassetid://" before the numbers; when you manually insert the numbers it puts it there for you, but when you do it through a script, you have to say "rbxassetid://" before the numbers

so for your shirt you would say "rbxassetid://7195910588" as the id

in your script it would look like this


Player.Shirt.ShirtTemplate = "rbxassetid://7195910588"

i've tested this on my own shirt and it works for me

1 comment

0

its not a requirement to say "rbxassetid://" for this, you could simply say: "http://www.roblox.com/asset/?id=7195910588"

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