Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tool kills the player? [Attempt at FE Damaging]

So this tool is supposed to kill any player it touches EXCEPT the player. I've even made it detect if a player is the same player that is holding tool. The issue that lies is that it's still killing the player!

LocalScript inside Tool:

local tool = script.Parent
local debounce = false
local equipsound = tool.Sounds.Equip
local slashsound = tool.Sounds.Slash
local killsound = tool.Sounds.Kill
local isActive = script.Parent:WaitForChild("Values").isActive
local replicatedstorage = game:GetService("ReplicatedStorage")
print("Loaded...")



tool.Equipped:Connect(function(Mouse)
		print("Loaded....")
		equipsound:Play()
		Mouse.Icon = "rbxasset://textures/GunCursor.png"
		local char = script.Parent.Parent
		local knifehold = char.Humanoid:LoadAnimation(script.Parent.Animations.KnifeHold)
		knifehold:Play()
		tool.Activated:Connect(function()
			if debounce == false then
				print("Loaded.....")
				isActive.Value = true
				debounce = true
				slashsound:Play()
				local chosenanim = math.random(1,3)
				print("Loaded......")
				local anim = script.Parent.Animations["Slash"..chosenanim]
				local slash1 = char.Humanoid:LoadAnimation(anim)
				slash1:Play()
				wait(0.5)
				isActive.Value = false
				debounce = false
			end
		end)
		tool.Unequipped:Connect(function()
			knifehold:Stop()
			Mouse.Icon = ""
		end)
end)

tool.Handle.Touched:Connect(function(hit)
	if hit and hit.Parent and hit.Parent:WaitForChild("Humanoid") then
		if hit.Parent.Humanoid.Health > 0 then
			if hit.Parent ~= game.Players.LocalPlayer.Character and hit.Parent.Parent ~= game.Players.LocalPlayer.Character then
				replicatedstorage.KillEvent:FireServer(hit.Parent)
				killsound:Play()
			end
		end
	end
end)

ServerScript inside Tool:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KillEvent = ReplicatedStorage:WaitForChild("KillEvent")

KillEvent.OnServerEvent:Connect(function(player)
	local plr = game.Workspace[player.Name]
	plr.Humanoid:TakeDamage(100)
end)

1 answer

✓ Accepted answer

it's because on the server script, you're asking it to kill the player who fired the event. The first argument in .OnServerEvent is always the player sending the request. the second argument is what the player is firing.

your ServerScript, fixed.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KillEvent = ReplicatedStorage:WaitForChild("KillEvent")

KillEvent.OnServerEvent:Connect(function(player,arg1)
	local plr = game.Workspace:FindFirstChild(arg1.Name)
	if plr and plr:FindFirstChild('Humanoid') then
		plr.Humanoid:TakeDamage(100)
	end
end)

2 comments

0

thanks, but does this mean i have to edit my localscript to say ":FireServer(player,argument)"

0

nope. when the server gets the request, the first argument is the player. the second argument from the server is the first argument the client fired.

This discussion is preserved as it was. New answers, comments, and votes are closed.