Why can't attempt to index this

I wrote it correctly… Help,

problem is Character.Head.Position section

Remote.OnServerEvent:Connect(function(player, mousePosition, key, character)
	if not AttackAble then return end
	print('throw')
	AttackAble = false
	if Humanoid and Humanoid.RigType == Enum.HumanoidRigType.R15 then
		Remote:FireClient(getPlayer(), "PlayAnimation", "Animation")
	end
	local targetPos = mousePosition.p
	local lookAt = (targetPos - Character.Head.Position).unit
	Toss(lookAt)
	LeftDown = true
end)

1 Like

“Character” is undefined. You only have “character” replace it with “character” instead.
(it is just the difference of the capital C.)

It should look like this:

local lookAt = (targetPos - character.Head.Position).Unit
1 Like

I don’t think you can fire the character to the server, use player.Character

1 Like

This is the solution of your problem

Remote.OnServerEvent:Connect(function(player, mousePosition, key, character)
	if not AttackAble then return end
	print('throw')
	AttackAble = false
	local Humanoid = character.Humanoid
	if Humanoid and Humanoid.RigType == Enum.HumanoidRigType.R15 then
		Remote:FireClient(getPlayer(), "PlayAnimation", "Animation")
	end
	local targetPos = mousePosition.p
	local lookAt = (targetPos - character.Head.Position).unit
	Toss(lookAt)
	LeftDown = true
end)
1 Like

That is not true. You can pass a Model to the server.
My solution above would have worked and would be useful if this was for a weapon. (if you wanted to get the player’s enemy’s character.) If this were for a weapon, make sure that you check the validity of the character provided.

This only worked because it happens to be that the character you are passing through the RemoteEvent is the sender’s character. If you are trying to make something happen to the sender’s character, then use player.Character, if not do not use it.

I would like to note that the only reason why your script didn’t work is because you had a capital c on the word character.

Even if it is true, there is no reason to pass an extra variable from the client.

1 Like
  1. I said it was not true. (false)
  2. I stated the use cases for my solution. It would not be an extra variable in the use case I provided. Considering we have no extra context, one may think that it is for a weapon.

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