-
What do you want to achieve? I’m trying to achieve to make a system were you cannot hit other players, but you can only hit the zombies. (Due to abuse, as this is for an event.)
-
What is the issue? I have these guns, and I am a beginner so I dont really know what I do.
-
What solutions have you tried so far? I looked at the developer hub but there was no help there.
You could try adding a bool value into the zombie and if your weapon detects the bool value then it will take the amount of damage required. (my first post, sorry if its wrong)
What about the players, will it cause any damage to them?
No, unless that the bool value is also inside the players character. Could you show me the script where it deals the damage and maybe I can help some more.
That is the reload function for the gun, can you show me the part where the damage is dealt ? sorry I’m really bad at this lol
or this local tool = script.Parent.Parent
local player = game:GetService(“Players”).LocalPlayer
local mouse = player:GetMouse()
local hole = tool:WaitForChild(“Hole”)
local handle = tool:WaitForChild(“Handle”)
local actionService = game:GetService(“ContextActionService”)
local mouseDown = false
local equipped = false
local animations = tool:WaitForChild(“Animation”)
local configs = tool:WaitForChild(“Configs”)
local remotes = tool:WaitForChild(“Remotes”)
local bindable = tool:WaitForChild(“Bindable”)
local recoilAnim = animations:WaitForChild(“Recoil”)
local reloadAnim = animations:WaitForChild(“Reload”)
local holdAnim = animations:WaitForChild(“Hold”)
local recoilTrack
local reloadTrack
local holdTrack
local allowTracing = configs:WaitForChild(“AllowTracing”)
local range = configs:WaitForChild(“Range”)
local canShoot = remotes:WaitForChild(“CanShoot”)
local canReload = remotes:WaitForChild(“CanReload”)
local hitRemote = remotes:WaitForChild(“Hit”)
local reloadRemote = remotes:WaitForChild(“Reload”)
local shootRemote = remotes:WaitForChild(“Shoot”)
local flashGui = hole:WaitForChild(“FlashGui”)
local reloadBind = bindable:WaitForChild(“Reload”)
local function equip()
equipped = true
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
if humanoid then
pcall(function()
holdTrack = humanoid:LoadAnimation(holdAnim)
holdTrack:Play()
end)
pcall(function()
wait(0.1)
reloadTrack = humanoid:LoadAnimation(reloadAnim)
end)
pcall(function()
recoilTrack = humanoid:LoadAnimation(recoilAnim)
end)
end
end
local function unequip()
equipped = false
if holdTrack then
holdTrack:Stop()
end
if reloadTrack then
reloadTrack:Stop()
end
if recoilTrack then
recoilTrack:Stop()
end
end
local function reload()
if canReload:InvokeServer() then
reloadRemote:FireServer()
if reloadTrack then
reloadTrack:Play()
end
end
end
local function fire()
if canShoot:InvokeServer() then
if recoilTrack then
recoilTrack:Play()
end
flashGui.Enabled = true
local ray = Ray.new(hole.CFrame.p, (mouse.hit.p - hole.CFrame.p).unit * range.Value)
local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true)
if touch then
hitRemote:FireServer(touch)
end
shootRemote:FireServer()
wait()
flashGui.Enabled = false
end
end
tool.Equipped:Connect(function()
equip()
end)
mouse.Button1Up:Connect(function()
mouseDown = false
end)
tool.Activated:Connect(function()
mouseDown = true
repeat
wait(0.01)
fire()
until not mouseDown
end)
tool.Unequipped:Connect(unequip)
reloadBind.Event:Connect(reload)
Sorry, I’m getting very confused I’m not sure If I can help. sorry
For situations like these where you want a certain group of people to get affected by something, I’d use CollectionService, where you can tag specific NPCs as Zombies and Players as Players.
Uh, I believe bool value is choice.
I place a bool value in just the zombies or the player?
Zombies, Make sure when hit, :FindFirstChild(“Value”) if it doesn’t exist, function just ends. Or if it exists, fire remote event.
should i put it in a single script?
if touch then
hitRemote:FireServer(touch)
end
Make it checks if there is BoolValue
You can make an Anti-Team kill script
function onHumanoidDied(humanoid, player)
local killer = getKillerOfHumanoidIfStillInGame(humanoid)
if (killer ~= nil) then
handleTKs(player, killer)
end
end
function onPlayerRespawn(property, player)
if property == "Character" and player.Character ~= nil then
local humanoid = player.Character.Humanoid
local p = player
local h = humanoid
humanoid.Died:connect(function() onHumanoidDied(h, p) end )
end
end
function getKillerOfHumanoidIfStillInGame(humanoid)
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
local killer = tag.Value
if killer.Parent ~= nil then
return killer
end
end
return nil
end
function handleTKs(player, killer)
if (killer.TeamColor == player.TeamColor) then
killer.Character.Humanoid.Health = 0
end
end
function onPlayerEntered(newPlayer)
while true do
if newPlayer.Character ~= nil then break end
wait(3)
end
local humanoid = newPlayer.Character.Humanoid
humanoid.Died:connect(function() onHumanoidDied(humanoid, newPlayer) end )
newPlayer.Changed:connect(function(property) onPlayerRespawn(property, newPlayer) end )
end
game.Players.ChildAdded:connect(onPlayerEntered)
Put this script inside the gun(s)