I have two scripts, a LocalScript in StarterPlayerScripts, and the other in StarterCharacterScripts. The jist of these scripts is that its meant to activate a function to kill another player when youre close enough to them and press R.
The LocalScript seems to work as intended, but the other one doesn't activate. The output doesn't appear to show any errors, either. Any help would be greatly appreciated.
Player = game.Players:GetPlayerFromCharacter(script.Parent)
local kicktarget = nil
S = 0
D = 0
function onFiredKick()
local playerlist = game.Players:GetChildren()
local num = 1
for i = 1, #playerlist do
if playerlist[num].Character:WaitForChild("IsKnockedDown").Value == true and playerlist[num] ~= Player then
local ray = Ray.new(Player.Character.Torso.Position, playerlist[num].Character.Torso.Position)
local Killpart, hitpos = workspace:FindPartOnRay(ray, Player.Character)
if Killpart.Parent == playerlist[num].Character and ray:Distance() <= 4 then
Player.Character.Humanoid:MoveTo(playerlist[num].Character.Torso.Position)
kicktarget = playerlist[num].Character
end
end
num = num+1
end
end
function onKill(target)
S = math.random(1,1)
if S == 1 and D == 0 then
D = 3
local killanim = game.ReplicatedStorage.Animations.Kills.Kill1A
local killanimtrack = Player.Character.Humanoid:LoadAnimation(killanim)
killanimtrack:Play()
local dieanim = game.ReplicatedStorage.Animations.Kills.Kill1V
local dieanimtrack = target.Humanoid:LoadAnimation(dieanim)
dieanimtrack:Play()
wait(1.8)
target.Humanoid:TakeDamage(100100)
end
end
function onReachTarget()
if kicktarget ~= nil then
onKill(kicktarget)
end
end
--script.onKick.OnServerEvent:Connect(onFiredKick)
game.ReplicatedStorage.onKick.OnServerEvent:Connect(onFiredKick)
Here's the LocalScript code, too, if that helps.
player = game.Players.LocalPlayer
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
--player.Character:WaitForChild("KickScript").onKick:FireServer()
game.ReplicatedStorage.onKick:FireServer()
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
