.Touched not working

You can write your topic however you want, but you need to answer these questions:
I have a game where one team places shields to stop the other teams’ bullets, The bullets then damage the shields if they are hit, using a .Touched event to do so. The Problem is that the .Touched does not touch the shield. This worked in the past, and as far as I am aware, stopped working when I combined the scripts that make the bullet and the shield.

ServersideScript

local BulletEvent=game.ReplicatedStorage.Bulletevent
local Sheildevent=game.ReplicatedStorage.SheildEvent
local Damager=game.ServerStorage.Damager
local CanPlace=script.CanPlace
local RunService=game:GetService("RunService")

local function makepart(Type,parent,Name,position,anchor,size,transparency,CanColide,CanQuery,CanTouch,Attach0,Attach1)
	local part=Instance.new(Type)
	part.Parent=parent
	part.Name=Name
	if Type=="Part" then
		part.Position=position
		part.Anchored=anchor
		part.Size=size
		part.Transparency=transparency
		part.CanCollide=CanColide
		part.CanQuery=CanQuery
		part.CanTouch=CanTouch
		part.TopSurface=Enum.SurfaceType.Smooth
		part.BottomSurface=Enum.SurfaceType.Smooth
	elseif Type=="Attachment" then
		part.Position=position	
	elseif Type=="PrismaticConstraint" then
		part.Attachment0=Attach0
		part.Attachment1=Attach1
		part.ActuatorType=Enum.ActuatorType.Motor
	end

	return part
end

local function infrastructuremaker(position,BSize)
	local model=makepart("Model",game.Workspace,"Bullet")
	local bullet=makepart("Part",model,"Bullet",position+Vector3.new(0,BSize.Y/2,0),false,BSize,0,false,false,true)
	local Basepart=makepart("Part",model,"Anchor",position+Vector3.new(-4,BSize.Y/2,0),true,Vector3.new(2,2,2),1,false,false,false)
	local attachment1=makepart("Attachment",Basepart,"AnchorAttachemt",Vector3.new(1,0,0))
	local attachment2=makepart("Attachment",bullet,"BulletAttachemt",Vector3.new(-1,0,0))
	local Prism=makepart("PrismaticConstraint",bullet,"PrismaticConstraint",nil,nil,nil,nil,nil,nil,nil,attachment1,attachment2)
	Prism.MotorMaxForce=1000000
	return bullet,Prism,model
end

BulletEvent.OnServerEvent:Connect(function(player,position,speed,damage,Bsize)
	if CanPlace.Value then
		task.spawn(function()
			local bullet,Prism,model=infrastructuremaker(position,Bsize)
			Prism.Velocity=speed

			bullet.Touched:Connect(function(hit)
				print(hit.Name)
				if hit.Name=="Sheild" then
					model:destroy()
					local durability=hit:FindFirstChild("Durability")
					local strength=hit:FindFirstChild("Strength")
					local colordown=math.round(162/strength.Value)
					local deletecolor=Color3.fromRGB(colordown,colordown,colordown)
					durability.Value=durability.Value-damage

					if durability.Value<=0 then
						hit:destroy()
					end

					for i=1,damage do
						hit.Color=Color3.new(hit.Color.R-deletecolor.R,hit.Color.G-deletecolor.G,hit.Color.B-deletecolor.B)	
					end
				elseif hit.Name=="Goal" then
					Damager:Fire(damage)
				end
			end)
			wait(10)
			model:destroy()
		end)
	end
end)

Sheildevent.OnServerEvent:Connect(function(player,position,durabilityValue,Size,Lifespan)
	if CanPlace.Value then
		task.spawn(function()
			local sheild=makepart("Part",game.Workspace,"Sheild",position+Vector3.new(0,(Size.Y/2)-0.5,0),true,Size,0)
			local durability=makepart("NumberValue",sheild,"Durability")
			durability.Value=durabilityValue
			local Strength=makepart("NumberValue",sheild,"Strength")
			Strength.Value=durabilityValue
		end)
	end
end)
1 Like

Found the issue, Apparently setting .CanTouch=Nil makes it false

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