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

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

Asked by 2 years ago
Edited 2 years ago

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'

0
~~~~~~~~~~~~~~~~~ local Player = game.Players.LocalPlayer.Character function click() Player.Shirt.ShirtTemplate = 7195910588 end script.Parent.MouseButton1Click:connect(click) ~~~~~~~~~~~~~~~~~ Maybe try this Mimas18Hun 0 — 2y

2 answers

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
2 years ago
Edited 2 years ago

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) 
0
Fixed a minor error! JesseSong 3916 — 2y
Ad
Log in to vote
0
Answered by
Iou_is 0
2 years ago

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

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

Answer this question