"Cannot concatenate "hit" a userdata value"

Not entirely sure what I’m doing wrong here. The code is pretty much the same before a transition to a Client -> Server -> Client system was added to reduce server strain, and also to make projectile weapons more responsive. I’m getting an error of “cannot concatenate” and I have no clue what that means. The code doesn’t error unless I attempt to print something. This is used for my killfeed script, and no killfeed values are created upon the function, hitProjectile, is called.

Here is my code:

--Function

function hitProjectile(weapon,vPlayer,hit)
if weapon.Name == "Weapon" then
print(hit.Name)
print(vPlayer.Name)
print(weapon.Name)
end
end
--Portion of code that calls said function

explosion.Hit:Connect(function(hit)
hitProjectile(weapon,vPlayer,hit)
end)

Concatenation is where you are trying to join a string with another string Eg:
Joining “Hello” and “World” is done like this “Hello”…“World”, outputting “HelloWorld” A userdata value can’t be joined to a string value.

1 Like

So why was it working before, but is no longer working now?

It’s still all done inside of a server script.

From the code that you posted, it doesn’t look like you are trying to concatenate anything… Is there anywhere in the server script that you have written two dots? (… but two)

1 Like

Yeah, this bit right here.

If you comment that line of code and run the game again does the script throw the error?

Nope.

Though I completely forgot I only sent the name of the weapon to the server; not the object. Also forgot to put “.Name” after the hit variable in the print statement.

I should really stop programming so late at night.

Thanks for your help though! :slight_smile:

1 Like

No worries! :smile:

2 Likes