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

What's wrong in my script which giving decal on torso?

Asked by 3 years ago

Hello! I made script which giving decal on torso when you gonna click brick, but it's not working any ideas what's wrong?

This is this script

local brick = script.Parent
local decal = brick:findFirstChild("Decal")

script.Parent.ClickDetector.MouseClick:connect(function(player)
    local humanoid = player.Parent:findFirstChild("Humanoid")
    local torso = player.Parent:findFirstChild("Torso")
    if torso ~= nil and humanoid ~= nil then
        local shirt = player.Parent:findFirstChild("Shirt Graphic")
        if shirt ~= nil then
            shirt.Graphic = decal.Texture
        else
            local altshirt = torso:findFirstChild("roblox")
            if altshirt ~= nil then
                altshirt.Texture = decal.Texture
            else
                print("Torso found. Shirt not found. Assumed to be a robot.")
            end
        end
    else
        print("Not a valid person! T-Shirt cannot be changed!")
    end
end)

1 answer

Log in to vote
1
Answered by
k3du53 162
3 years ago

The ClickDetector.MouseClick event passes a player as it's one and only argument.

The problems I see are in lines 5 and 6, where you try to find Humanoid and Torso as a child of the parent of the player. (which is essentially trying to find the player's humanoid and torso in game.Players)

There is a property of the player that refers to the player's character in the workspace. To reference it, use player.Character instead of player.Parent.

Relevant links:

ClickDetector.MouseClick

player.Character

1
Works, thank you ThadonROOX 47 — 3y
Ad

Answer this question