I have a local script that fires a remote event when the tool is activated and a script when the remote event is fired it will damage a NPC. My game is filtering enabled.
Local Script:
local sword = tool:WaitForChild("Sword")
local swordblade = sword:WaitForChild("Blade")
local trail = swordblade:WaitForChild("Trail")
local handle = tool:WaitForChild("Handle")
local swing = handle:WaitForChild("Swing")
local switch = tool:WaitForChild("CanAttack")
local event = tool:WaitForChild("Event")
tool.Equipped:connect(function()
local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Idle)
idle:Play()
end)
tool.Activated:connect(function()
-------------------------------
event:FireServer() --fires an event in the tool
-------------------------------
switch.Value = true
local choose = math.random(1,3)
if choose == 1 then
local swing1 = script.Parent.Parent.Humanoid:LoadAnimation(script.Swing1)
swing1:Play()
swing:Play()
trail.Enabled = true
elseif choose == 2 then
local swing2 = script.Parent.Parent.Humanoid:LoadAnimation(script.Swing2)
swing2:Play()
swing:Play()
trail.Enabled = true
elseif choose == 3 then
local swing3 = script.Parent.Parent.Humanoid:LoadAnimation(script.Swing3)
swing3:Play()
swing:Play()
trail.Enabled = true
end
end)
tool.Deactivated:connect(function()
wait(2)
trail.Enabled = false
switch.Value = false
end)
tool.Unequipped:connect(function()
local hum = char:WaitForChild("Humanoid")
for _,anim in pairs(hum:GetPlayingAnimationTracks()) do
anim:Stop()
end
end)
Script:
local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local flesh = handle:WaitForChild("Hit")
local blade = tool:WaitForChild("Blade")
local detect = tool:WaitForChild("CanAttack")
local event = tool:WaitForChild("Event")
-------------------------
event.OnServerEvent:connect(function(plr) --reacts to the remote event being fired
-------------------------
blade.Touched:connect(function(hit)
local hum = hit.Parent:FindFirstChild("NPC")
if hum then
if detect.Value == true then
print(hum.Name)
detect.Value = false
for i,v in pairs(hit.Parent:GetChildren()) do
if v:IsA("IntValue") then
v:Destroy()
end
end
local kill = Instance.new("IntValue",hit.Parent)
kill.Name = script.Parent.Parent.Name
detect.Value = false
flesh:Play()
hum:TakeDamage(13)
wait(1)
detect.Value = true
end
end
end)
end)
I don't understand what is wrong with my scripts as it works in studio but not in a real game and it has no errors.

2 comments
https://scriptinghelpers.org/blog/it-works-in-studio-but-not-online
Just realized that I didn't need the remote event and it was just a scripting error. Thanks for the info, too.