Touched event does not fire

Here is the code.

local Sight = script.Parent.Sight

Sight.Touched:Connect(function()
	script.Parent.SeesTarget:FireServer(true)
	print("Touched")
end)

Sight.TouchEnded:Connect(function()
	script.Parent.SeesTarget:FireServer(false)
	print("TouchEnded")
end)

The touched event does not fire
This script is on client I have tried it on server as well

1 Like

Where are the scripts located exactly? Can you provide screenshots?

2 Likes

Does your part have the property CanTouch disabled?

1 Like

first of all where is the localscript located?

3 Likes

In a model of a rig the rig is in workspace

1 Like

Is sight inside of the rig? The problem is most likely the path of the Sight variable

2 Likes

Sight is inside the rig, so the script should work

2 Likes

If the script is inside of workspace, then it won’t work because local scripts don’t run in workspace

1 Like

On the server, It also doesn’t work so i am completly clueless right now

2 Likes

Yea but it’s a LocalScript right? I am just assuming that because you are trying to send information to the Server. Where is the Script located at?

2 Likes

The serverScript is in the model, Same place as the local script

1 Like

Local scripts don’t work in the workspace, so you might not want to do that. I can’t really tell what the issue is with the server one because we don’t know which parts of the rig you’re referring to or what you’re trying to accomplish, what is Sight? Could you provide screenshots?

3 Likes

is sight even a part? does it have CanTouch enabled?

1 Like

also why dont you remove the :FireServer events that could be the potential cause why it’s not working

1 Like

Yes it is a part with cantouch enabled

2 Likes

I have tried to remove them and i changed the script to only be a server script but it still doesn’t work

1 Like

alright give me your code without the :FireServer()

2 Likes

I have moved the touched event to the server script it was firing to

local fire = script.Fire
fire = script.Parent.Humanoid.Animator:LoadAnimation(fire)
local MeshId = "rbxassetid://2837888103"
local D = game:GetService("Debris")
local Hit
local canShoot = false
local Sight = script.Parent.Sight
local SeeingTarget = false

function Shoot()
	local bullet = script.Bullet:Clone()
	bullet.Parent = workspace
	bullet.Transparency = 0
	bullet.Position = script.Parent["M4A1 Model"].BarrelCover.Attachment.WorldPosition
	bullet.Orientation = Vector3.new(math.random(1, 360), math.random(1, 360))
	bullet.AssemblyLinearVelocity = Vector3.new(10, 10, 2)
	bullet.AssemblyLinearVelocity = Vector3.new(10, -10, 2)
	D:AddItem(bullet, 5)
	fire:Play()
	wait(.1)
	bullet.AssemblyLinearVelocity = Vector3.zero
	task.wait(0.05)
	local Part =  script.Part:Clone()
	game:GetService("Debris"):AddItem(Part, 10)
	Part.Parent = workspace
	Part.Transparency = 0
	Part.Position = script.Parent["M4A1 Model"].BarrelCover.Attachment.WorldPosition
	Part.Orientation = Vector3.new(0, 0, 0)
	local Attachment = Instance.new("Attachment", Part) -- the attachment used in Linearvelocity

	local LV = Instance.new("LinearVelocity", Attachment) -- creating the linear velocity
	LV.MaxForce = math.huge -- no need to worry about this
	LV.VectorVelocity = script.Parent.HumanoidRootPart.CFrame.lookVector * 100 -- change 100 with how fast you want the projectile to go
	LV.Attachment0 = Attachment-- setting the attachment
	script.Part.Script:Clone().Parent = Part
	task.wait(.2)
end

Sight.Touched:Connect(function(Part)
	seeingTarget = true
end)

Sight.TouchEnded:Connect(function()
	seeingTarget = false
end)



while SeeingTarget == true do
	Shoot()
end
2 Likes

you should use .Changed functions.

while SeeingTarget == true do
	Shoot()
end

this will not always detect if SeeingTarget is true

2 Likes

It gives an error
17:32:25.801 Workspace.Rig.Script:50: attempt to index boolean with ‘Changed’ - Server - Script:50

2 Likes