Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Cancollide is true for only one npc sword?

Asked by
Rdumb1 -15
2 months ago
Edited 2 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 -15 — 2mo
0
Are you copying that exact script into all of the other ones? blockmask 351 — 2mo
0
Is your script currently a local script? proGamergirl2468 30 — 2mo
0
nope. Just a normal script Rdumb1 -15 — 2mo
View all comments (3 more)
0
the script is INSIDE the handle of the sword, correct? and its duplicated into every handle? proGamergirl2468 30 — 2mo
0
ye the script is inside the handle, and its the same script on the second npc's sword handle. Rdumb1 -15 — 2mo
0
I now know (or think I know) whats wrong, I'll post my answer as an actual answer in a moment. proGamergirl2468 30 — 2mo

2 answers

Log in to vote
0
Answered by 2 months ago

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 -15 — 2mo
0
you're very welcome ??? PoppyandNeivaarecute 22 — 2mo
Ad
Log in to vote
1
Answered by 2 months ago

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!

Answer this question