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

TakeDamage is not a valid member of Part?

Local script

--Variabili
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local buco = script.Parent:FindFirstChild("Buco")
local tool = script.Parent
local evento = game:GetService("ReplicatedStorage"):FindFirstChild("Sparo")
local raggio = game.StarterPack.Tool.raggio.Value

--Funzione
tool.Equipped:Connect(function()
	mouse.Button1Down:Connect(function()
		print("Click")
		local ray = Ray.new(buco.CFrame.p, (mouse.Hit.p - buco.CFrame.p) * raggio) --Crea il raggio
		local bersaglio, position = workspace:FindPartOnRay(ray, player.Character)
		if bersaglio then
			local humanoid = bersaglio.Parent:FindFirstChild("Humanoid")
			if humanoid then
				evento:FireServer(player, bersaglio, humanoid)
			end
		end
	end)
end)

Server script

local danno = game.StarterPack.Tool.danno.Value
local evento = game:GetService("ReplicatedStorage"):FindFirstChild("Sparo")

evento.OnServerEvent:Connect(function(player, bersaglio, humanoid)
	print(player, bersaglio, humanoid)
	if bersaglio.Name == "Head" then
	humanoid:TakeDamage(danno * 2) else
		humanoid:TakeDamage(danno)
	end
end)

Output

  Click
  bucaniere  bucaniere  Right Arm
  21:12:40.251 - TakeDamage is not a valid member of Part

Hello. This is my second post. I am having trouble with the humanoid which in the output is said to be a Part. Can anyone help me solve this issue? The comments and the variables are in Italian so I can understand them better, fell free to ask for the translated scripts if needed. Sorry if this question sounds silly but as I said in my previous post, I'm still learning. Thanks in advance.

2 answers

✓ Accepted answer

:FireServer already passes the player argument.

event:FireServer("hello")

event.OnServerEvent:Connect(function(plr,message)
	print(message) --> "hello"
end)

1 comment

0

Thanks. That solved my problem.

Just remove player from evento:FireServer(player, bersaglio, humanoid). Because it's automatically in there even if you wont.

--Variabili
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local buco = script.Parent:FindFirstChild("Buco")
local tool = script.Parent
local evento = game:GetService("ReplicatedStorage"):FindFirstChild("Sparo")
local raggio = game.StarterPack.Tool.raggio.Value

--Funzione
tool.Equipped:Connect(function()
    mouse.Button1Down:Connect(function()
        print("Click")
        local ray = Ray.new(buco.CFrame.p, (mouse.Hit.p - buco.CFrame.p) * raggio) --Crea il raggio
        local bersaglio, position = workspace:FindPartOnRay(ray, player.Character)
        if bersaglio then
            local humanoid = bersaglio.Parent:FindFirstChild("Humanoid")
            if humanoid then
                evento:FireServer(bersaglio, humanoid)
            end
        end
    end)
end)

1 comment

1

I did not know that. I'll keep that in mind.

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