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

ServerScriptService.Punch Server:3: Expected identifier, got '('?

game.ReplicatedStorage.Remotes.Punch.OnServerEvent:Connect(function(player,damage)
	for i,target in pairs(game.Workspace:GetDescendants()) do
		if target.("Humanoid") and target.Parent.Name ~= player.Name then
			if (target.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude <5 then
				target.Character.Humanoid.Health -= damage
			end
		end
	end
end)

I don't know the problem on line 3 its so annoying :/

1 comment

0

Help me lol

2 answers

✓ Accepted answer
  1. :GetDescendats() Gets Everything Including Model Names. So use :GetChildren()
  2. target.("Humanoid") does not need that infact it needs target:FindFirstChild("Humanoid") 2.5. ("Humanoid") is not required but you could use ["name here"] if it has any special characters.

tip: tip 2.5 doesnt work on everything so if you have a object called "dh h8" you do not need to code it like parent:FindFirstChild("["dh h8"]") you need to code it like parent:FindFirstChild("dh h8") or parent:FindFirstChild([["dh h8"]]) -- anything inside the double brackets count as a string

your modifyed code would look like:

game.ReplicatedStorage.Remotes.Punch.OnServerEvent:Connect(function(player,damage)
    for i,target in pairs(game.Workspace:GetChildren()) do
        if target:FindFirstChild("Humanoid") and target.Parent.Name ~= player.Name then
            if (target.Character.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).magnitude <5 then
                target.Character.Humanoid.Health -= damage
            end
        end
    end
end)

1 comment

0

Ok new problem lol is says

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