Still have questions? Join our Discord server and get real time help.
0

# Cancollide is true for only one npc sword?

Edited 6 months ago

So I'm making a game with npc's using swords which has a damage script but doesn't actually attack, I have a cancollided shield which can block the damage script for a lil. In the first npc's sword handle, I put this script in the handle.

game.Workspace["Bandit"].Sword.Handle.CanCollide = true


Its works for 1 npc but when I put the same script on the second npc, the npc sword isn't cancollided.

0
And does this need to be a local script? I'm not really experienced with scripting. Rdumb1 4 — 6mo
0
Are you copying that exact script into all of the other ones? blockmask 351 — 6mo
0
Is your script currently a local script? Ozzisiya 67 — 6mo
0
nope. Just a normal script Rdumb1 4 — 6mo
0
the script is INSIDE the handle of the sword, correct? and its duplicated into every handle? Ozzisiya 67 — 6mo
0
ye the script is inside the handle, and its the same script on the second npc's sword handle. Rdumb1 4 — 6mo
0
I now know (or think I know) whats wrong, I'll post my answer as an actual answer in a moment. Ozzisiya 67 — 6mo

0

You could giving the 'Bandits' different names such as 'bandit1' and 'bandit2'

Alternatively you could put the script in the handle, as you have, and use this code :

script.Parent.CanCollide = true


Basically it removes all the areas causing the problem, and also shortens the script a fair bit! I hope that this solves your problem ???

0
Thank you 2 for this! It works! Rdumb1 4 — 6mo
0
you're very welcome ??? PoppyandNeivaarecute 22 — 6mo
1

You could give the bandits different names, and or simply go about this another way. Here's why its wrong too.

Basically, because the models "Bandits" both have the same exact name, it randomly selects one of them because its confused as to what it should do. Instead of giving you an error, it selects one randomly.

You could name them "bandit1" or "bandit2" HOWEVER, if that ruins any other scripts you have, (which I feel like it will) you can do the following.

Put the script inside the handle (still a normal script) and it says the following

script.Parent.CanCollide = true


It gets the script, the script itself, gets the parent of it (the handle because its in the handle) and sets cancollide to true. I hope this helps!

if you have any questions, comment!