So in this code i,m changing the Template ID of a model and want to change it for the Player itself but i don't get any Errors or Warnings and it only changes the model appearance. So does anybody know why?
script.Parent.MouseButton1Click:Connect(function() local Modul = game.Workspace.Starter.StarterCharacter.Shirt Modul.ShirtTemplate = "http://www.roblox.com/asset/?id=28984380" playername = script.Parent.Parent.Parent.Parent.Parent.Parent.Name player = Workspace:FindFirstChild(""..playername.."") if player ~= nil then player:FindFirstChild("Shirt").PantsTemplate = "http://www.roblox.com/asset/?id=28984380" end end)
GENERAL PRACTICE
Use Activated
instead of MouseButton1Click
since Activated
works for all devices and not just computers
Use workspace
instead of game.Workspace
; workspace is lowercase, not uppercase as in Line 6
In a LocalScript, the player can be called from the LocalPlayer Instance of the Players
Service
Use :WaitForChild()
to make sure a part / model exists before using, defining, or changing it
ISSUES
PantsTemplate
is not a valid Property of Shirt
Instances.
REVISED LOCAL SCRIPT
local player = game:GetService("Players").LocalPlayer local id = "http://www.roblox.com/asset/?id=28984380" script.Parent.Activated:Connect(function() local Modul = workspace:WaitForChild("Starter"):WaitForChild("StarterCharacter"):WaitForChild("Shirt") Modul.ShirtTemplate = id local character = player.Character if character:FindFirstChild("Shirt") then character.Shirt.ShirtTemplate = id end end)
I also suggest performing this on the Server either with a RemoteEvent
to connect the client to the server or just directly with the PlayerAdded
event. More on this can be found here:
https://developer.roblox.com/api-reference/class/RemoteEvent
I'll be happy to take any questions or comments regarding these methods or the above code.