I have a script inside of a tool and when that tool hits a player, the script detects it and fires a BindableEvent. That then passes the player who got hit’s information over and Knocks/Downs them. I have a few issues with it though, first of all the timer does not show up on the BillboardGui I created nor does it change color. Second of all I don’t know if the Knocking script should be a server or client script (it is a server script right now), because I think the server script only functions one at a time. Here are the scripts:
KnockingScript (Server, Inside ServerScriptService):
local RS = game:GetService("ReplicatedStorage")
local BE = RS.ReviveBE
local KnockedAnim = script:WaitForChild("KnockedAnim")
local BBG = game.ServerStorage.BillboardGui
local BBGE = game.ReplicatedStorage.RemoteEvents.BillboardGuiEvent
local ReviveSound = script.ReviveSound
local Timer = 30
local revivePrompt = game.ServerStorage.RevivePrompt
local CC = RS.ColorChanger
local CC2 = RS.ColorChanger2
local knocked = false
local TimerPaused = false
local StopTimer = false
BE.Event:Connect(function(playerThatWasHit)
wait(0.5)
print("Player was hit:", playerThatWasHit)
local Humanoid = playerThatWasHit.Character and playerThatWasHit.Character:FindFirstChild("Humanoid")
if Humanoid then
if knocked == false then
knocked = true
Humanoid.WalkSpeed = 8
local KAP = Humanoid.Animator:LoadAnimation(KnockedAnim)
KAP:Play()
local ClonedBBG = BBG:Clone()
ClonedBBG.Parent = Humanoid.Parent.Head
local ClonedRP = revivePrompt:Clone()
ClonedRP.Parent = Humanoid.Parent.UpperTorso
ClonedRP.ActionText = "Recover " ..playerThatWasHit.name
local function startTimer()
local remainingTime = Timer
while remainingTime > 0 do
if TimerPaused == false then
if StopTimer == false then
BBGE:FireAllClients(playerThatWasHit, remainingTime)
wait(1)
remainingTime -= 1
print(remainingTime)
if remainingTime <= 0 then
Humanoid.Health = 0
print("Timer ran out, Humanoid died")
ClonedBBG:Destroy()
ClonedRP:Destroy()
end
else
print("Timer Stopped")
StopTimer = false
break
end
else
print("Timer Paused")
wait(1)
end
end
end
local TimerCoroutine = coroutine.create(startTimer)
coroutine.resume(TimerCoroutine)
ClonedRP.Triggered:Connect(function()
KAP:Stop()
Humanoid.WalkSpeed = 16
ReviveSound:Stop()
StopTimer = true
task.wait(0.1)
ClonedRP:Destroy()
ClonedBBG:Destroy()
knocked = false
print("PromptTriggered")
end)
ClonedRP.PromptButtonHoldBegan:Connect(function()
ReviveSound:Play()
CC:FireAllClients()
print("Begining Hold")
TimerPaused = true
end)
ClonedRP.PromptButtonHoldEnded:Connect(function()
ReviveSound:Stop()
CC2:FireAllClients()
print("Stopped Holding")
TimerPaused = false
end)
else
return
end
end
end)
ToolDetectionScript (Server, Inside of the tool in StarterPack):
local DebounceTable = {}
local RS = game:GetService("ReplicatedStorage")
local BE = RS.ReviveBE
script.Parent:WaitForChild("HitBox").Touched:Connect(function(hitPart)
if hitPart.Parent and hitPart.Parent:WaitForChild("Humanoid") then
local playerCharacter = hitPart.Parent
local player = game.Players:GetPlayerFromCharacter(playerCharacter)
if player then
if DebounceTable[player] == true then return end
DebounceTable[player] = true
BE:Fire(player)
--print("Successfully fired the BindableEvent")
wait(2)
DebounceTable[player] = nil
else
print("Not a player")
end
end
end)
BillboardGuiScript (Client, Inside the text label in the BillboardGui in ServerStorage):
local replicatedStorage = game:GetService("ReplicatedStorage")
local BillBoardGuiEvent = replicatedStorage.RemoteEvents.BillboardGuiEvent
local textlabel = script.Parent
local Revivetextlabel = script.Parent.Parent.ReviveIP
local CC = replicatedStorage.ColorChanger
local CC2 = replicatedStorage.ColorChanger2
BillBoardGuiEvent.OnClientEvent:Connect(function(player, remainingTime)
if player == game.Players.LocalPlayer then
textlabel.Text = tostring(remainingTime)
end
end)
CC.OnClientEvent:Connect(function()
Revivetextlabel.TextColor3 = Color3.new(0, 0.666667, 0)
Revivetextlabel.Text = "Recovery In Progress"
end)
CC2.OnClientEvent:Connect(function()
Revivetextlabel.TextColor3 = Color3.new(1, 0, 0)
Revivetextlabel.Text = "Awaiting Recovery"
end)