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

Character not being detected?

I have a LocalScript in a tool that makes it so it would change your "toolnone" animation when you equip/unequip it but it somehow fails to detect the character even though it's super clear.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character

if plr:FindFirstChild("Character") then
	print("character detected")
	else print("not detected")
end


script.Parent.Equipped:Connect(function()
	repeat wait(0.5)
	char:FindFirstChild("Humanoid"):FindFirstChild("Animate"):FindFirstChild("toolnone"):FindFirstChild("ToolNoneAnim").AnimationId = "rbxassetid://3827795087"
	until char:FindFirstChild("Humanoid"):FindFirstChild("Animate"):FindFirstChild("toolnone"):FindFirstChild("ToolNoneAnim").AnimationId == "rbxassetid://3827795087"
end)

script.Parent.Unequipped:Connect(function()
	repeat wait(0.5)
	char:FindFirstChild("Humanoid"):FindFirstChild("Animate"):FindFirstChild("toolnone"):FindFirstChild("ToolNoneAnim").AnimationId = "rbxassetid://3827799534"
	until char:FindFirstChild("Humanoid"):FindFirstChild("Animate"):FindFirstChild("toolnone"):FindFirstChild("ToolNoneAnim").AnimationId == "rbxassetid://3827799534"
end)

It prints "not detected" just for some extra evidence

1 answer

you can get the character by saying the reason you're not getting the character in your code is because the character takes a few seconds to load into game. the player loads before the character.

character = game.Workspace:WaitForChild(plr.Name)

--or 

character = game.Players.LocalPlayer.Character 

1 comment

0

problem is, it won't detect the character even if I give it time to load, which I find super strange

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