Attack Script for the Npc:
Texture.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then local char = hit.Parent if char.Shared:FindFirstChild("Check1") then -- Checking if player doesn't have the Value else local Int = Instance.new('BoolValue',char.Shared) Int.Name = "Check1" Int.Value = true end
Npc Died Script:
for _,p in pairs(game.Players:GetPlayers()) do if p.Character.Shared.Check1.Value == true then print (p.Name.." Gain the loot") p.Character.Shared.Check1:Remove() end end
I'm not sure if this would give everyone in the game the same loot or would it just give the player that has "Check1" in there Character the Loot and not everyone else. Is there a better way of doing this?
Your problem is that the Check1 value may not reside in the current player you're checking on line 2 of the Died script. Check if 'Check1' exists prior to indexing the value.
Attack;
Texture.Touched:connect(function(hit) if hit.Parent:FindFirstChild('Humanoid') then local shared = hit.Parent.Shared if not shared:FindFirstChild("Check1") then local Int = Instance.new("BoolValue",shared) Int.Name = "Check1" Int.Value = true end end end
Died;
for _,p in pairs(game.Players:GetPlayers()) do local val = p.Character.Sharacter:FindFirstChild("Check1") if val then if val.Value then print (p.Name.." gained the loot") val:Destroy() --remove is deprecated end end end