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

how to make this weapon not hurt players and only damage npcs?

Asked by 3 years ago

local Snowflake = script.Parent

local Services = { Players = (game:FindService("Players") or game:GetService("Players")), TweenService = (game:FindService("TweenService") or game:GetService("TweenService")), RunService = (game:FindService("RunService") or game:GetService("RunService")), Debris = (game:FindService("Debris") or game:GetService("Debris")), ReplicatedStorage = (game:FindService("ReplicatedStorage") or game:GetService("ReplicatedStorage")), Lighting = (game:FindService("Lighting") or game:GetService("Lighting")), ServerScriptService = (game:FindService("ServerScriptService") or game:GetService("ServerScriptService")) }

function IsInTable(Table,Value) for _,v in pairs(Table) do if v == Value then return true end end return false end

function IsTeamMate(Player1, Player2) return (Player1 and Player2 and not Player1.Neutral and not Player2.Neutral and Player1.TeamColor == Player2.TeamColor) end

function TagHumanoid(humanoid, player) local Creator_Tag = Instance.new("ObjectValue") Creator_Tag.Name = "creator" Creator_Tag.Value = player Services.Debris:AddItem(Creator_Tag, 2) Creator_Tag.Parent = humanoid end

function UntagHumanoid(humanoid) for i, v in pairs(humanoid:GetChildren()) do if v:IsA("ObjectValue") and v.Name == "creator" then v:Destroy() end end end

delay(7,function() Snowflake:Destroy() end)

local Puff = script:WaitForChild("Puff") Puff.Parent = Snowflake Puff.Enabled = true

local Creator = script:WaitForChild("Creator")

local Touch

Touch = Snowflake.Touched:Connect(function(hit) if not hit or not hit.Parent then return end local Hum = hit.Parent:FindFirstChildOfClass("Humanoid") local FF = hit.Parent:FindFirstChildOfClass("ForceField") if FF or not Hum or Hum.Health <= 0 or IsTeamMate(Creator.Value,Services.Players:GetPlayerFromCharacter(Hum.Parent)) or Creator.Value == Services.Players:GetPlayerFromCharacter(Hum.Parent) then return end Touch:Disconnect();Touch = nil UntagHumanoid(Hum) TagHumanoid(Hum) Hum:TakeDamage(270) local function Frozen(Character) -- Quick check to see if they're not frozen for _,v in pairs(Services.ServerScriptService:GetChildren()) do if v:IsA("Script") and v.Name == "Freeze" and v:FindFirstChild("Target") and v:FindFirstChild("Target").Value == Hum.Parent then return true end end return false end if not Frozen(Hum.Parent) then local FreezeScript = script:WaitForChild("Freeze"):Clone() FreezeScript:WaitForChild("Creator").Value = Creator.Value FreezeScript:WaitForChild("Target").Value = Hum.Parent FreezeScript.Parent = Services.ServerScriptService FreezeScript.Disabled = false end Snowflake:Destroy() end) i'm trying to find a way to make it so that the snowflakes don't harm players and only npcs this is a script for staff of neverending frost and i tested it on my friend by firing a snowflake at him and it damaged him and i wanna fix that need help the answers i got earlier we're bad

0
Put this in a code block. CoolBlueJay000 48 — 3y
0
I can hardly read this. Please put your code into a code block. 2_MMZ 1059 — 3y
0
Code block, code block. code block. NarwhalAndMe 141 — 3y
0
idk how to do that dylancrazy88 20 — 3y

1 answer

Log in to vote
0
Answered by
sifn 70
3 years ago

The function :GetPlayerFromCharacter() is used when needing to distinguish real players from NPCs all the time. In your case, you would want to verify that whatever is being attacked is not a player before dealing damage to it, since you prefer that only NPCs can be subject to player attacks.

local IsPlayer = game.Players:GetPlayerFromCharacter(victim_of_the_attack)
if IsPlayer then return end -- It is an attempt to attack a real player, so do nothing

-- Deal damage to the NPC here!

I see the function already present in your code so I understand that you probably already know how to use it, but I decided on a friendly reminder nonetheless.

Even more, Here is the documentation of :GetPlayerFromCharacter on Roblox's developer hub.

0
i'm actually new to coding it's that i took a staff of neverending frost from library and used it dylancrazy88 20 — 3y
0
Format your code and I might be able to tell you where to work this in. sifn 70 — 3y
Ad

Answer this question