I have 3 scripts that (together) determine if a player kills another player. If it does then it announces the kill to the entire server and processes a bounty, etc. The entire script chain works perfectly, except for the player who was killed. Weirdly, the final script partially runs and then hangs on the last step.
LocalScript to Determine Character Death & Fire Server Event (in StarterCharacterScripts)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hitbox = character:WaitForChild("playerHitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local events = replicatedStorage:WaitForChild("Events")
local touchEvent = events:WaitForChild("touchEvent")
local db = true
local function touchPlayer(object)
if db then
db = false
if object.Parent.Name == "target" then
touchEvent:FireServer()
task.wait(5)
end
task.wait(1)
db = true
end
end
hitbox.Touched:Connect(touchPlayer)
Script to Kill Player, Award Points, and Fire RemoteEvent back to All Clients (in ServerScriptService)
local repStore = game:GetService("ReplicatedStorage")
local events = repStore:FindFirstChild("Events")
local touchEvent = events:WaitForChild("touchEvent")
local killedEvent = events:WaitForChild("killedEvent")
local dss = game:GetService("DataStoreService")
local gameVersion = "1"
local function killPlayer(player)
local Players = game:GetService("Players")
local targetCharacter = game.Workspace:WaitForChild("target")
local targetPlayer = Players:GetPlayerFromCharacter(targetCharacter)
local targetPlayerUserID = targetPlayer.UserId
local killerBounty = player:WaitForChild("PlayerStats"):WaitForChild("Bounty")
local killerCash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local targetPlayerStats = targetPlayer:WaitForChild("PlayerStats")
local targetPlayerLeaderstats = targetPlayer:WaitForChild("leaderstats")
local targetPlayerCash = targetPlayerLeaderstats:WaitForChild("Cash")
local targetPlayerBounty = targetPlayerStats:WaitForChild("Bounty")
local targetHumanoid = targetCharacter:FindFirstChild("Humanoid")
local cashStolen = math.floor(targetPlayerCash.Value / 2)
local totalBounty = targetPlayerBounty.Value + cashStolen
targetPlayerCash.Value = targetPlayerCash.Value - cashStolen
killerBounty.Value = killerBounty.Value + math.floor(targetPlayerBounty.Value / 4)
killerCcash.Value = killerCash.Value + totalBounty
local playerData = dss:GetDataStore(gameVersion)
local data = {
["Cash"] = targetPlayerCash.Value
}
playerData:SetAsync(targetPlayerUserID,data)
targetHumanoid.Health = 0
killedEvent:FireAllClients(player,targetPlayer,targetPlayerBounty.Value,cashStolen)
end
touchEvent.OnServerEvent:Connect(killPlayer)
LocalScript to Broadcast Kill to All Players (in StarterGui)
local replicatedStorage = game:GetService("ReplicatedStorage")
local events = replicatedStorage:WaitForChild("Events")
local killedEvent = events:WaitForChild("killedEvent")
local gameVersion = "1"
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local playerSystemMsg = playerGui:WaitForChild("systemMessage"):WaitForChild("Frame"):WaitForChild("systemMsgLabel")
local playerBanner = playerGui:WaitForChild("Banner"):WaitForChild("Frame"):WaitForChild("bannerLabel")
local function playerKilled(playerKiller,targetKilled,targetPlayerBounty,cashStolen)
playerSystemMsg.Text = tostring(playerKiller).." killed "..tostring(targetKilled)..", collecting a Bounty of "..tostring(targetPlayerBounty).." and stealing "..tostring(cashStolen).." Cash!"
playerSystemMsg.Visible = true
task.wait(5)
playerSystemMsg.Visible = false
end
killedEvent.OnClientEvent:Connect(playerKilled)
This single line from the last script runs for all Clients except the player that was killed.
playerSystemMsg.Visible = false
Essentially, the broadcast message appears, and then disappears for all players. On the player that died, it appears, but never goes away.