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

Why isnt this working? (Very short and easy code, and its in a localscript)

Asked by 10 years ago
script.Parent.ClickDetector.MouseClick:connect(function(p)
local Torso = game.Players.LocalPlayer.Character:WaitForChild("Torso")

Torso.Anchored = true
    if p.Backpack:findFirstChild("Fish") then
        p.Backpack:findFirstChild("Fish").Handle.Mesh.VertexColor = Vector3.new(0.4,0.4,0.4)
wait(2)
Torso.Anchored = false




    end
end)

0
Only the torso anchored thing doesnt work iipartyhat 25 — 10y

2 answers

Log in to vote
0
Answered by
jav2612 180
10 years ago
script.Parent.ClickDetector.MouseClick:connect(function(p)
    local Torso = p.Character:WaitForChild("Torso")

    Torso.Anchored = true
        if p.Backpack:findFirstChild("Fish") then
            p.Backpack:findFirstChild("Fish").Handle.Mesh.VertexColor = Vector3.new(0.4,0.4,0.4)
        wait(2)
        Torso.Anchored = false
    end
end)


I'm not sure why you were trying to use LocalPlayer when MouseClick returns the player?

Ad
Log in to vote
0
Answered by
Axstin 55
10 years ago

When the MouseClick event is fired, it gives the player who clicked as an argument, in this case 'p.'

Try this.

script.Parent.ClickDetector.MouseClick:connect(function(p)
    if p.Character then -- Checks if the players character isn't nil
        local torso = p.Character:FindFirstChild("Torso")
        local fish = p.Backpack:FindFirstChild("Fish")

        if torso then -- if torso exists
                torso.Anchored = true

                if fish then -- if fish exists
                    p.Backpack.Fish.Handle.Mesh.VertexColor = Vector3.new(0.4,0.4,0.4)
                    wait(2)
                end

                torso.Anchored = false
        end
    end
end)

Answer this question