Little help with Touch event

Okay so i’m creating a VR game (using nexus vr thingy since idk how to create my own ‘multiplayer vr’)

But i’m having a bit of trouble with the sword script.
in vr if the Collision is enabled it can collide with the ground and stuff (obviously) but if u have it in hand and point it at the ground it glitches weirdly.

So i thought of just having CanCollide disabled and making a script that enabled when it sees a specific part. In this case it would be a part named “part” inside a tool.
So i tried putting one tool model of that sword in workspace and one in starterpack for you to equip. But it doesnt seem to work.

pictures and script >>>

image
image
image

local tool = game:GetService("StarterPack"):WaitForChild("Tool") -- Replace with the path to your tool in the StarterPack
local partA = workspace.Sword.Blade -- Replace with the part in the Workspace
local partB = tool.Blade -- Replace with the part in the tool

local function onPartATouched(otherPart)
	if otherPart:IsDescendantOf(tool) and otherPart == partB then
		-- partA touched partB in the tool
		partA.CanCollide = true
		partB.CanCollide = true
		print("partA touched partB in the tool!")
	else
		partA.CanCollide = false
		partB.CanCollide = false
		print("Parts aren't touching")
	end
end

-- Connect the Touched event of partA
partA.Touched:Connect(onPartATouched)


Have you checked if the CanTouch property is on? If it isn’t, turn it back on because this determines if the .Touched events will fire in this part.

1 Like

Yes, the CanTouch property is enabled
image

I think it has to do with line one of your script.

Try this script:

although it didn’t work. it did bring me a bit closer.

so what it does is as normal yeah it enables the collision but it doesnt do it on both swords. it kinda acts like an switch now :woman_shrugging:

and it kinda makes sense that its just script.parent lol

If you put the script inside each tool ?

yeah, it’s in both tools exactly the same. copy pasted.

I don’t know if this is what you were going for, but instead of using a .touched event to make them collide, why don’t you try a collision group instead?

Make a collision group here, under the “Model” tab:

This could replace the script in each sword:

PhysicsService = game:GetService("PhysicsService")

Tool = script.Parent

-- Assign tool blade to pre-made group
Tool.Blade.CollisionGroup = "Swords"

-- Make it so they can't collide with anything else but each other
PhysicsService:CollisionGroupSetCollidable("Swords","Default", false)
PhysicsService:CollisionGroupSetCollidable("Swords","Swords", true)

If you want to learn more about collision groups, a link to the documentation is here

1 Like

oh wow i completely forgot about collision groups, it never even crossed my mind.

I will definitely try this out. If it works how i have it in mind it makes the parry system easier to work with.

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