Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

Only the torso anchored thing doesnt work

2 answers

✓ Accepted answer
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?

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.