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

How can I make that function only works when the player has a Shirt named "shirt"?

Asked by 5 years ago
Edited by Gey4Jesus69 5 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

So, basically the script is to morph the player into Sasuke (anime character) and it already works. But I want to make it only works when the player has a Shirt named "shirt". That's the script

local Tool = script.Parent;
local SasukeClassicShirt = game.ReplicatedStorage.Clothes.SasukeClassicShirt:Clone()    
local SasukeClassicPants = game.ReplicatedStorage.Clothes.SasukeClassicPants:Clone()  
local SasukeClassicFace = game.ReplicatedStorage.SasukeClassicFace:Clone()

Tool.Equipped:Connect(function()
    player = script.Parent.Parent
    player.Humanoid.MaxHealth = player.Humanoid.MaxHealth + 9999999
    player.Humanoid.Health = player.Humanoid.MaxHealth
    player.Shirt:remove()
    SasukeClassicShirt.Parent = player
    player.Pants:remove()
    SasukeClassicPants.Parent = player
    player.Head.face:remove()
    SasukeClassicFace.Parent = player.Head
    local SSJHair = game.ReplicatedStorage.SSJHair:Clone()
    SSJHair.Parent = player
    SSJHair.CFrame = player.Torso.CFrame
    local Weld = Instance.new("Weld")
    Weld.Name = "SSJ"
    Weld.Parent = player.Head
    Weld.Part0 = player.Head
    Weld.Part1 = SSJHair
    Weld.C0 = CFrame.new(0.05, 0.5, 0.4) * CFrame.Angles(0,math.pi,0)
    Weld.C1 = CFrame.fromOrientation(0, -179.2, 0)
    Tool:remove()
end)
0
player:FindFirstChild("shirt") DeceptiveCaster 3761 — 5y
0
You also may want to update your “remove” to “Destroy” ABK2017 406 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

All you need to do is add a simple conditional statement after your Equipped event. Also, note that :remove() is deprecated. Use :Destroy() instead.

local Tool = script.Parent;
local SasukeClassicShirt = game.ReplicatedStorage.Clothes.SasukeClassicShirt:Clone()    
local SasukeClassicPants = game.ReplicatedStorage.Clothes.SasukeClassicPants:Clone()  
local SasukeClassicFace = game.ReplicatedStorage.SasukeClassicFace:Clone()

Tool.Equipped:Connect(function()
    player = script.Parent.Parent
    if player:FindFirstChild("shirt") then
        player.Humanoid.MaxHealth = player.Humanoid.MaxHealth + 9999999
        player.Humanoid.Health = player.Humanoid.MaxHealth
        player.Shirt:Destroy()
        SasukeClassicShirt.Parent = player
        player.Pants:remove()
        SasukeClassicPants.Parent = player
        player.Head.face:remove()
        SasukeClassicFace.Parent = player.Head
        local SSJHair = game.ReplicatedStorage.SSJHair:Clone()
        SSJHair.Parent = player
        SSJHair.CFrame = player.Torso.CFrame
        local Weld = Instance.new("Weld")
        Weld.Name = "SSJ"
        Weld.Parent = player.Head
        Weld.Part0 = player.Head
        Weld.Part1 = SSJHair
        Weld.C0 = CFrame.new(0.05, 0.5, 0.4) * CFrame.Angles(0,math.pi,0)
        Weld.C1 = CFrame.fromOrientation(0, -179.2, 0)
        Tool:Destroy()
    end
end)
Ad

Answer this question