# My projectile duplicates on my client, and the Health variable gets subtracted twice, but when shot on server the projectile works fine

**URL:** <https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974>\
**Category:** World Creation\
**Tags:** Variable, Server, client-replication, unreal-engine, projectile, Blueprint, question\
**Created:** [August 19, 2018, 5:22pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974 "2018-08-19T17:22:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CheesyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CheesyBro](https://forums.unrealengine.com/u/CheesyBro)\
**Post date:** [August 19, 2018, 5:22pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/1 "2018-08-19T17:22:56Z")

</div>

I have a projectiles that gets shot from the character, and every character has a health value. When the server fires the projectile it works fine, but when the client does the hit actor’s health value gets subtracted twice (40) when it should only be subtracted with 20. I tried various multicasting and run on server variations to no luck.

 ![250945-cast-and-decrease.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/9/b/09b4a77ee99fa22df331b1df2bb428cd9b80a166.png)

---

<div class="post-metadata">

**Author:** ![erikdubbelboer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@erikdubbelboer](https://forums.unrealengine.com/u/erikdubbelboer)\
**Post date:** [August 19, 2018, 5:46pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/2 "2018-08-19T17:46:57Z")

</div>

Sounds like you are spawning the particle both on the server and client. If you want the client to trigger an event like spawning a projectile you will have to have it trigger an event on the server which in turn triggers a different multicasting event that actually does the spawning. All communication always has to go trough the server for other clients to get it. A client can’t multicast to other clients.

---

<div class="post-metadata">

**Author:** ![CheesyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CheesyBro](https://forums.unrealengine.com/u/CheesyBro)\
**Post date:** [August 19, 2018, 5:56pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/3 "2018-08-19T17:56:07Z")

</div>

You mean like this? This subtracts the health twice as well.

 ![250946-changed1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/b/b/cbb6c024ad8dcfbb532508242161acd65ddd9a8e.png)

---

<div class="post-metadata">

**Author:** ![erikdubbelboer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@erikdubbelboer](https://forums.unrealengine.com/u/erikdubbelboer)\
**Post date:** [August 19, 2018, 6:14pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/4 "2018-08-19T18:14:34Z")

</div>

Yes that should make the projectile spawn only once if it is triggered by a client. Now calculating the damage is something that only the server should do. So the projectile on the client is only for cosmetics. The code that calculates the damage should have an “Is Server” check before it. This is assuming your health variable is replicated.

---

<div class="post-metadata">

**Author:** ![CheesyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CheesyBro](https://forums.unrealengine.com/u/CheesyBro)\
**Post date:** [August 19, 2018, 6:19pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/5 "2018-08-19T18:19:49Z")

</div>

Well the whole damage and stat setting event is set to run on server. But I can try putting an Is Server right when the even triggers.

---

<div class="post-metadata">

**Author:** ![CheesyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CheesyBro](https://forums.unrealengine.com/u/CheesyBro)\
**Post date:** [August 19, 2018, 6:45pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/6 "2018-08-19T18:45:45Z")

</div>

Okay I did but the problem still exists. Also now for some reason I spawn two projectiles. One of them instantly hits me and the other one flies into the server dealing twice as much damage.

---

<div class="post-metadata">

**Author:** ![CheesyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CheesyBro](https://forums.unrealengine.com/u/CheesyBro)\
**Post date:** [August 19, 2018, 7:42pm UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/7 "2018-08-19T19:42:44Z")

</div>

I managed to fix it! I set it back to how it originally was, and in the Cast and Decrease macro I just put a switch has authority between the input and the Set Health so only the Server side sets the Variable not the client as well. Thanks for the help 😃

---

<div class="post-metadata">

**Author:** ![erikdubbelboer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@erikdubbelboer](https://forums.unrealengine.com/u/erikdubbelboer)\
**Post date:** [August 20, 2018, 1:45am UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/8 "2018-08-20T01:45:05Z")

</div>

That doesn’t sound like a proper fix to me. Your problem is that de Decreasehealth even is triggered from both the client and server projectile. You should add an “Is Server” check before you tigger that event. Not an “Has Authority” check seeing as the client has authority over it’s own projectile as it was spawned there.

Another option would be to only spawn the projectile on the server and make it replicated. But this is obviously heavier as the projectile position would need to be replicated all the time.

---

<div class="post-metadata">

**Author:** ![CheesyBro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CheesyBro](https://forums.unrealengine.com/u/CheesyBro)\
**Post date:** [August 20, 2018, 9:54am UTC](https://forums.unrealengine.com/t/my-projectile-duplicates-on-my-client-and-the-health-variable-gets-subtracted-twice-but-when-shot-on-server-the-projectile-works-fine/431974/9 "2018-08-20T09:54:05Z")

</div>

It works both ways. But I will use your solution since it seems more performance and network friendly! Thank you! 🙂
