I made my own guns but if people are on a different team it still doesn’t damage. What could be the problem?
Script:
if raycastResult then
local hitpart = raycastResult.Instance
local model = hitpart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
local players = game:GetService("Players")
if players:GetPlayerFromCharacter(model) then
local TargetPlayer = players:GetPlayerFromCharacter(model)
if TargetPlayer.Neutral or player.Neutral or TargetPlayer.Team ~= player.Team and Settings["Anti-TK"] == true then
local hum = model.Humanoid
untagHumanoid(hum)
tagHumanoid(hum, player)
model.Humanoid.Health = model.Humanoid.Health - Settings.Damage.Value
end
else
model.Humanoid.Health = model.Humanoid.Health - Settings.Damage.Value
end
end
end
end
local Gun = script.Parent
local Settings = Gun:WaitForChild("Settings")
Gun.Events.Reload.OnServerEvent:Connect(function()
Gun.Handle.Reload:Play()
end)
local function tagHumanoid(hum, player)
local Creator_Tag = Instance.new("ObjectValue", hum)
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
local debris = game:GetService("Debris")
debris:AddItem(Creator_Tag, 2)
end
local function untagHumanoid(hum)
for i,v in pairs(hum:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
Gun.Events.Fire.OnServerEvent:Connect(function(player, mousePos)
Gun.Handle.Fire:Play()
Gun.Handle.Flare.ParticleEmitter:Emit(100)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*300,raycastParams)
local part = Instance.new("Part", script.Parent)
part.Anchored = true
game.Debris:AddItem(part,.02)
part.CanCollide = false
part.CanTouch = false
part.CanQuery = false
part.Size = Vector3.new(.001,.001,.001)
part.Transparency = 1
local att = Instance.new("Attachment", part)
local direction2 = (mousePos - script.Parent.Handle.Flare.WorldPosition).Unit
part.Position = script.Parent.Handle.Flare.WorldPosition + direction2*2000
script.Parent.Handle.Beam.Attachment1 = att
if raycastResult then
local hitpart = raycastResult.Instance
local model = hitpart:FindFirstAncestorOfClass("Model")
if model then
if model:FindFirstChild("Humanoid") then
local players = game:GetService("Players")
if players:GetPlayerFromCharacter(model) then
local TargetPlayer = players:GetPlayerFromCharacter(model)
if TargetPlayer.Neutral or player.Neutral or TargetPlayer.Team ~= player.Team and Settings["Anti-TK"] == true then
local hum = model.Humanoid
untagHumanoid(hum)
tagHumanoid(hum, player)
model.Humanoid.Health = model.Humanoid.Health - Settings.Damage.Value
end
else
model.Humanoid.Health = model.Humanoid.Health - Settings.Damage.Value
end
end
end
end
for i,v in pairs(Gun.Handle.Flare:GetChildren()) do
if v:IsA("PointLight") then
v.Enabled = true
wait(0.1)
v.Enabled = false
end
end
end)
Try adding brackets to split the if statement around? I feel like that and might be messing stuff up when combined with or’s. Also I feel like Anti-TK is a boolValue, in which case you forgot to get the Value
Not sure how you want to compare exactly but I think the brackets should encase the last 2 comparisions
if TargetPlayer.Neutral or player.Neutral or (TargetPlayer.Team ~= player.Team and Settings["Anti-TK"].Value == true) then