I have a script within my NPC that correctly gives cash to the player when the player kills the NPC. I had to insert a script within the NPC to call a remote event, but I'm not quite sure how to do that with an actual player. I need to give 10 cash when a player kills another player. What am I doing wrong here? (FYI this is inside my save data, hence the other stuff in there.)
Look at lines 25-32. That is where I am checking if the player died to give money to whoever killed them.
local function onPlayerAdded(player) local playerKey = "Player_" .. player.UserId wait() print("User ".. player.UserId.. " Joined") local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local Cash = Instance.new("IntValue") Cash.Name = "Cash" Cash.Parent = leaderstats local myCash local success, err = pcall(function() myCash = CashStore:GetAsync(playerKey) or STARTING_CASH end) if success then Cash.Value = myCash print("loading "..myCash) else print("failed to retrieve data") warn(err) end player.CharacterAdded:Connect(function(Character) Character.Humanoid.Died:Connect(function(Died) local creator = Character.Humanoid:FindFirstChild("creator") local leaderstats = creator.Value:FindFirstChild("leaderstats") if creator ~= nil and creator.Value ~= nil then leaderstats.Cash.Value = leaderstats.Cash.Value + 10 end end) end) game.ServerStorage.Give.Event:Connect(function(Amount) wait() Cash.Value = Cash.Value + Amount end) end game.Players.PlayerAdded:Connect(onPlayerAdded)