You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Hello I am new here .I am working on a 2ww game. And I have encountered a problem. I am not good at scripting let alone coding weapons so I took a ready made model. I noticed that the weapon works in such a way that it kills a person from the team. I wanted to change it so it doesn’t do that but I don’t know how. Is it possible to do it somehow
I looked in the posts but there was nothing like this
If it’s the wrong category then sorry write me I will change it.
It would be very helpful if you could send some code snippets instead of an entire object!
But I’d suspect the code at some point does
humanoid.Health -= 50 -- Or whatever the damage is
If you find this, you should be able to prevent damage by doing:
local tgtPlr = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
-- Deal damage if it was an NPC OR if the players have different teams
if not tgtPlr or plr.Team ~= tgtPlr.Team then
humanoid.Health -= 50
end
Sorry but I can’t find it
The scripts are quite chaotic should I look for this in gunScriptserver?
or in local script?
This is gun server
local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local Player
local Character
local Humanoid
--local TEAM
local VisualizeBullet = script.Parent:WaitForChild("VisualizeBullet")
local Module = require(Tool:WaitForChild("Setting"))
local ChangeAmmoAndClip = script:WaitForChild("ChangeAmmoAndClip")
local InflictTarget = script:WaitForChild("InflictTarget")
local Grip2
local Handle2
if Module.DualEnabled then
Handle2 = Tool:WaitForChild("Handle2",1)
if Handle2 == nil and Module.DualEnabled then error("\"Dual\" setting is enabled but \"Handle2\" is missing!") end
end
local AmmoValue = script:FindFirstChild("Ammo") or Instance.new("NumberValue",script)
AmmoValue.Name = "Ammo"
AmmoValue.Value = Module.AmmoPerClip
local ClipsValue = script:FindFirstChild("Clips") or Instance.new("NumberValue",script)
ClipsValue.Name = "Clips"
ClipsValue.Value = Module.LimitedClipEnabled and Module.Clips or 0
if Module.IdleAnimationID ~= nil or Module.DualEnabled then
local IdleAnim = Instance.new("Animation",Tool)
IdleAnim.Name = "IdleAnim"
IdleAnim.AnimationId = "rbxassetid://"..(Module.DualEnabled and 53610688 or Module.IdleAnimationID)
end
if Module.FireAnimationID ~= nil then
local FireAnim = Instance.new("Animation",Tool)
FireAnim.Name = "FireAnim"
FireAnim.AnimationId = "rbxassetid://"..Module.FireAnimationID
end
if Module.ReloadAnimationID ~= nil then
local ReloadAnim = Instance.new("Animation",Tool)
ReloadAnim.Name = "ReloadAnim"
ReloadAnim.AnimationId = "rbxassetid://"..Module.ReloadAnimationID
end
if Module.ShotgunClipinAnimationID ~= nil then
local ShotgunClipinAnim = Instance.new("Animation",Tool)
ShotgunClipinAnim.Name = "ShotgunClipinAnim"
ShotgunClipinAnim.AnimationId = "rbxassetid://"..Module.ShotgunClipinAnimationID
end
ChangeAmmoAndClip.OnServerEvent:connect(function(Player,Ammo,Clips)
AmmoValue.Value = Ammo
ClipsValue.Value = Clips
end)
InflictTarget.OnServerEvent:connect(function(Player,TargetHumanoid,TargetTorso,Damage,Direction,Knockback,Lifesteal,FlamingBullet)
if Player and TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso then
while TargetHumanoid:FindFirstChild("creator") do
TargetHumanoid.creator:Destroy()
end
local creator = Instance.new("ObjectValue",TargetHumanoid)
creator.Name = "creator"
creator.Value = Player
game.Debris:AddItem(creator,5)
TargetHumanoid:TakeDamage(Damage)
if Knockback > 0 then
TargetTorso.Velocity = Direction * Knockback
end
if Lifesteal > 0 and Humanoid and Humanoid.Health ~= 0 then
Humanoid.Health = Humanoid.Health + (Damage*Lifesteal)
end
if FlamingBullet then
local Debuff = TargetHumanoid.Parent:FindFirstChild("IgniteScript") or script.IgniteScript:Clone()
Debuff.creator.Value = Player
Debuff.Disabled = false
Debuff.Parent = TargetHumanoid.Parent
end
end
end)
Tool.Equipped:connect(function()
Player = game.Players:GetPlayerFromCharacter(Tool.Parent)
Character = Tool.Parent
Humanoid = Character:FindFirstChild("Humanoid")
--TEAM = Character:FindFirstChild("TEAM")
if Module.DualEnabled and Workspace.FilteringEnabled then
Handle2.CanCollide = false
local LeftArm = Tool.Parent:FindFirstChild("Left Arm")
local RightArm = Tool.Parent:FindFirstChild("Right Arm")
if RightArm then
local Grip = RightArm:WaitForChild("RightGrip",0.01)
if Grip then
Grip2 = Grip:Clone()
Grip2.Name = "LeftGrip"
Grip2.Part0 = LeftArm
Grip2.Part1 = Handle2
--Grip2.C1 = Grip2.C1:inverse()
Grip2.Parent = LeftArm
end
end
end
end)
Tool.Unequipped:connect(function()
if Module.DualEnabled and Workspace.FilteringEnabled then
Handle2.CanCollide = true
if Grip2 then Grip2:Destroy() end
end
end)
And Does it work on other objects that deal damage e.g. sword
InflictTarget.OnServerEvent:connect(function(Player,TargetHumanoid,TargetTorso,Damage,Direction,Knockback,Lifesteal,FlamingBullet)
local targetPlayer = game:GetService("Players"):GetPlayerFromCharacter(TargetHumanoid.Parent)
if targetPlayer and targetPlayer.Team == Player.Team then return end -- They were on the same team, abort
if Player and TargetHumanoid and TargetHumanoid.Health ~= 0 and TargetTorso then
Additional note: The script provided isn’t the best. There are plenty of issues with it, so I would get an actual scripter to replace it at some point down the line.
Thanks a lot I had a problem with this for two months
and you solved it in a moment
Does this piece work on all damage objects?
I ask for future time
local tgtPlr = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
-- Deal damage if it was an NPC OR if the players have different teams
if not tgtPlr or plr.Team ~= tgtPlr.Team then
humanoid.Health -= 50
end