Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Trying to make this not inflict self damage but having trouble, advise? [closed]

Asked by
Songist 49
5 years ago
Edited 5 years ago

I'm experimenting with some ROBLOX-Made gear, trying to see how different attributes, like force acting on an arrow, can be modified through simple NumValues. Had some problems in other areas though the I figure would be good to understand if anyone can help


local Tool = script.Parent local Remote = Tool:WaitForChild("Remote") local Handle = Tool:WaitForChild("Handle") local FriendlyFire = false local AttackDamage = 35 local AttackAble = true local AttackRestTime = 1 local ProjectileSpeed = 50 local MousePoint = Vector3.new() local Arrows = {} --returns the wielding player of this tool function getPlayer() local char = Tool.Parent return game:GetService("Players"):GetPlayerFromCharacter(char) end --helpfully checks a table for a specific value function contains(t, v) for _, val in pairs(t) do if val == v then return true end end return false end --tags a human for the ROBLOX KO system function tagHuman(human) local tag = Instance.new("ObjectValue") tag.Value = getPlayer() tag.Name = "creator" tag.Parent = human game:GetService("Debris"):AddItem(tag) end **--used by checkTeams function sameTeam(otherHuman) local player = getPlayer() local otherPlayer = game:GetService("Players"):GetPlayerFromCharacter(otherHuman.Parent) if player and otherPlayer then if player == otherPlayer then return true end if otherPlayer.Neutral then return false end return player.TeamColor == otherPlayer.TeamColor end return false end --use this to determine if you want this human to be harmed or not, returns boolean function checkTeams(otherHuman) return not (sameTeam(otherHuman) and not FriendlyFire) end** function getArrow() local arrow = Instance.new("Part") arrow.FormFactor = "Custom" arrow.Size = Vector3.new(0.2, 0.4, 3) arrow.TopSurface = "Smooth" arrow.BottomSurface = "Smooth" arrow.CanCollide = false local mesh = Instance.new("SpecialMesh") mesh.MeshType = "FileMesh" mesh.MeshId = "rbxassetid://223379254" mesh.TextureId = "rbxassetid://2740083062" mesh.Scale = Vector3.new(0.6, 0.6, 0.6) mesh.Parent = arrow local lift = Instance.new("BodyForce") lift.force = Vector3.new(0, 196.2, 0) * arrow:GetMass() * 0.9 lift.Parent = arrow local hit = Handle.Hit:Clone() hit.Parent = arrow hit.TimePosition = 0.2 local projectile = Tool.Projectile:Clone() projectile.Disabled = false projectile.Parent = arrow return arrow end function onLeftDown() if not AttackAble then return end AttackAble = false delay(AttackRestTime, function() AttackAble = true end) Remote:FireClient(getPlayer(), "PlayAnimation", "BowFire") wait(0.3) Handle.Shot.Pitch = math.random(90,110)/100 Handle.Shot:Play() local arrow = getArrow() arrow.CFrame = CFrame.new(Handle.Position, MousePoint) arrow.Velocity = arrow.CFrame.lookVector * ProjectileSpeed local c c = arrow.Touched:connect(function(part) if part:IsDescendantOf(Tool.Parent) then return end if contains(Arrows, part) then return end c:disconnect() arrow.Projectile:Destroy() local w = Instance.new("Weld") w.Part0 = part w.Part1 = arrow w.C0 = part.CFrame:toObjectSpace(arrow.CFrame) w.Parent = w.Part0 arrow.Hit:Play() ** if part.Parent and part.Parent:FindFirstChild("Humanoid") then local human = part.Parent.Humanoid if checkTeams(human) then tagHuman(human) human:TakeDamage(AttackDamage) end end end) ** table.insert(Arrows, arrow) arrow.Parent = workspace game:GetService("Debris"):AddItem(arrow, 10) end function onMouseUpdate(targetPoint) MousePoint = targetPoint end function onRemote(player, func, ...) if player ~= getPlayer() then return end if func == "LeftDown" then onLeftDown(...) elseif func == "UpdateMouse" then onMouseUpdate(...) end end Remote.OnServerEvent:connect(onRemote)

I bolded the main areas I'm focusing on. I've tried a few things, none of which are working, and a lot of this is possibly due to my difficulty understanding the first block of bolded code. It seems as though this provides a series of either true or false, but how does the code aggrigate these responses in the next part under checkteams()? It needs to be true to fire the later bolded code, but I'm just a bit confused as to how it got here. Thank you!

edit: Ahh bolding doesn't work here, lemme get the line numbers

ok, 42 - 61, and 128 - 135

Closed as Not Constructive by Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
1
Answered by 5 years ago

You can simply add another statement to avoid self-damage, this simply just doesn't deal damage or tags if the humanoid detected is your own, I didn't go through much of the code but hope this is what you need.

if checkTeams(human) and human ~= Player.Character.Humanoid then
    tagHuman(human)
    human:TakeDamage(AttackDamage)
end
Ad