ok so i have a script inside of a bomb that of course creates an explosion but it also creates a value of the player who placed it which both work fine but i am trying to figure out a way to make the game add points to a player that kills another player or players with said explosion
script that makes the owner value and clones the bomb
game.ReplicatedStorage.DropBomb.OnServerEvent:Connect(function(Player,Spot,RootPart) local Bomb = game.ReplicatedStorage.BombBag local Clone = Bomb:Clone() Clone.Parent = workspace Clone.Position = RootPart.Position - Vector3.new(3,0,0) local Owner = Instance.new("StringValue") Owner.Parent = Clone Owner.Value = Player.Name end)
localscript that that tells the server to make the bomb
local UIS = game:GetService("UserInputService") local player = game.Players.LocalPlayer local character = player.CharacterAdded:wait() local humanoid = character:WaitForChild("Humanoid") local RootPart = character.HumanoidRootPart local Spot = RootPart.Position local BombDropped = false game:GetService("UserInputService").InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.F then if not BombDropped then BombDropped = true game.ReplicatedStorage.DropBomb:FireServer(Spot,RootPart) wait(5) BombDropped = false end end end end)
sorry im not good at wording things
I don’t have time to write it all but assuming that leaderstats and player has been added, you would add something like this, obviously changing “money” and it’s “value” to whatever. If you then add some lines in your damage script, explosion, bullet damage whatever, you can choose under what conditions to meet that will award the owner. This is sort of a really long comment but too big for comments. I will try to expand on the damage and checking the value when I can if it’s not answered.
char.Humanoid.Died:Connect(function() If char.Humanoid:FindFirstChild(“creator”) ~= nil then local Tag = Instance.new(“StringValue”) tag.Value = char.Humanoid.creator.Value local Give = game.Players:FindFirstChild(Tag.Value) Give.leaderstats.money.Value = Give.leaderstats.money.Value + 100 Tag:Destroy() end end)
local function getCharacter(desc) while desc do if desc:FindFirstChildOfClass("Humanoid") then return desc.Parent end desc = desc.Parent end return nil end -- ... local explosion = Instance.new("Explosion") explosion.Hit:Connect(function(hit) local character = getCharacter(hit) if character then local creator = Instance.new("ObjectValue") creator.Name = "creator" creator.Value = playerWhoCreatedExplosion creator.Parent = character end end) explosion.Parent = workspace
All that's left is to connect a function to the Died event of a player character's Humanoid upon spawn and have it check the character model for an ObjectValue object pointing the killer