I am working on a taser in Roblox studio and I use collection service to connect to the taser, my script has no error and red line but it didn’t work. Can someone fix this?
Server(Server Script):
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local stunnedTime = 5
local function fire(target, position, item)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {target.Character}
params.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(item.Handle.Position, (position - item.Handle.Position) * 80, params)
if result then
local hit = result.Instance
local model = hit:FindFirstAncestorOfClass("Model")
if model and model.Name == "Caty" then
print("Founded")
if model:FindFirstChild("Humanoid") then
local stunned = model.Humanoid:LoadAnimation(model.Humanoid.Stunned)
if model:FindFirstChild("Kill") then
model:FindFirstChild("Kill").Disabled = true
end
model.HumanoidRootPart.Anchored = true
model.Humanoid.WalkSpeed = 0
stunned:Play()
wait(stunnedTime)
model:FindFirstChild("Kill").Disabled = false
model.HumanoidRootPart.Anchored = true
model.Humanoid.WalkSpeed = 16
stunned:Stop()
end
end
end
end
for _, item in pairs(CollectionService:GetTagged("Item")) do
if item.Name == "Taser" then
events:WaitForChild("fireEvent").OnServerEvent:Connect(function(player, mousePos)
fire(player, mousePos)
end)
end
end
Client(Local Script):
local CollectionService = game:GetService("CollectionService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local function connect(click, event)
event:FireServer(click.Hit.p)
end
for _, item in pairs(CollectionService:GetTagged("Item")) do
if item.Name == "Taser" then
local taser = item
local mouse = game.Players.LocalPlayer:GetMouse()
local fireEvent = events:WaitForChild("fireEvent")
taser.Equipped:Connect(function()
mouse.Button1Down:Connect(function()
connect(mouse, fireEvent)
end)
end)
end
end
EDIT: Those script located in ServerScriptServie