Trying to get left arm of character R6

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I want to create a hit box to my punching animation.
The hitbox appears when the event on the animation has been passed.

  1. What is the issue? Include screenshots / videos if possible!

When I try to get the LeftArm of the character but I get nil.

local Players=game:GetService("Players")

print("this is raycast script")


--this is the attempt to get the elft arm of the character
Players.PlayerAdded:Connect(function(player)
	print("player added")
	local MyCharacter = player.Character or player.CharacterAdded:Wait()
	local Humanoid = player.Character:WaitForChild("Humanoid")
	script.Parent=MyCharacter
	
	local allowed = {
		"Left Arm"
	}

	for _, Obj in pairs(MyCharacter:GetChildren()) do
		if table.find(allowed, Obj.Name) ~= nil then
			script.Parent=Obj
			local LeftArm=Obj -- gives nil for some reason
			print("script has been parented2")
		end
	end
	
	
end)




local RS=game:GetService("ReplicatedStorage")
local hitboxEvent=RS.eventsAndFunctions.hitboxEvent

-- << Initial Setup >> 
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)

-- We will construct a new hitbox for our part
local newHitbox = RaycastHitbox.new(script.Parent)

local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {MyCharacter} --so that My character doesnt dammage himself from his own punch lol
Params.FilterType = Enum.RaycastFilterType.Blacklist




-- Makes a new event listener for raycast hits
newHitbox.OnHit:Connect(function(hit, humanoid)
	print(hit)
	humanoid:TakeDamage(50)
end)



-- at a certain part of animation we will create event when start fire ray cast
hitboxEvent.OnServerEvent:Connect(function(player,JabAnimationTrack)
	
	print("on server event :)")
	newHitbox:SetPoints(LeftArm, {Vector3.new(0, 0, 0)})
	newHitbox:HitStart()
	
	JabAnimationTrack.Stopped:Connect(function() -- when anim ends stop the hit box
		newHitbox:HitStop()
	end)
end)

also the script does recognize the left arm as it’s parent
image

1 Like

you are declaring the LeftArm variable inside the PlayerAdded function, the value won’t be accessed ouside that function. you need to declare it globaly.

try

local LeftArm
Players.PlayerAdded:Connect(function(player)
	print("player added")
	local MyCharacter = player.Character or player.CharacterAdded:Wait()
	local Humanoid = player.Character:WaitForChild("Humanoid")
	script.Parent=MyCharacter
	
	local allowed = {
		"Left Arm"
	}

	for _, Obj in pairs(MyCharacter:GetChildren()) do
		if table.find(allowed, Obj.Name) ~= nil then
			script.Parent=Obj
			LeftArm=Obj -- gives nil for some reason
			print("script has been parented2")
		end
	end
end)
2 Likes

still gives the same error

On line 20 you said “local LeftArm = Obj”, it’s inside another scope, at line 60 you try using a variable that does not exist, removing the “local” from line 20 should fix the missing LeftArm variable

I think that solved the error.
But the loop now doesn’t fire

You’re gonna find a lot of other issues if you are trying to make a multiplayer game

fr I’ll just mark his solution x)
I’ll check out the other stuff on my own

ty for calling me out tho, made me realise I’m using the dev forum a bit too much as a crutch.
I’ll try to not post anything onto here for a week, see what happens :slight_smile:

lol Solved it,
It’s because I parented it to left Arm so It was incapable of creating the variable afterwards

image

did some minor changes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.